Blog
How to Calculate the Manhattan Distance in Python
Distances measures are essential tools for machine learning. A distance measure is a score that summarises how different two objects are in the problem domain. Usually, we calculate distance measures on rows of data, like strings representing text documents. Specific...
Python SyntaxError: unexpected EOF while parsing Solution
"SyntaxError: unexpected EOF while parsing" occurs when the program finishes abruptly before executing all of the code. This error can happen when you make a structural or syntax mistake in the code, most likely a missing parenthesis or an incorrectly indented block....
How to Solve Python ValueError: invalid literal for int() with base 10 Solution
Invalid literal for int() with base 10 occurs when you try to convert an invalid object into an integer. Python is good at converting between different data types. When using the int() function, we must follow a specific set of rules. If we do not follow these rules,...
How to Check if a File or Directory Exists in Python
Checking if a specific file exists with Python is very useful. You may want to read data in to analyse or check if a file exists before writing data to file. There are three ways to check if a file exists using the os library: isfile(), isdir(), and exists. We will...
How to Get a Substring From a String in Python
Table of contentsWhat is a String?What is a Substring in Python?Using split()Using [start:]Using [:end]Using [start:end:step]Using List ComprehensionCheck if Substring Exists in SubstringSimilarities Between StringsPython String ComparisonSummary What is a String? A...
Python TypeError: can only concatenate str (not “int”) to str Solution
If we try to concatenate an integer with a string, we will raise the error "TypeError: can only concatenate str (not “int”) to str". This error occurs because you can only concatenate strings with other strings. In this tutorial, we will go through the error in detail...
How to Check Python Version for Linux, Mac, and Windows
Python is a popular programming language, widely used for data science and machine learning. The language comes with a wide range of libraries and packages, which have their versions and may require a specific version of Python. This article describes how to check and...
How to Calculate Cosine Similarity in Python
Table of contentsWhat is Cosine Similarity?How to Calculate Cosine SimilarityCosine DistanceVisual Description of Cosine SimilarityNumerical Example of Cosine SimilarityPython Example of Cosine SimilarityDifferences Between Cosine and Jaccard SimilaritySoft Cosine...
How to Calculate Jaccard Similarity in Python
Understanding the similarity between two objects is a universal problem. In machine learning, you can use similarity measures for various issues. These include object detection, classification and segmentation tasks in computer vision and similarity between text...
Python TypeError: list indices must be integers or slices, not str Solution
List indexing is a valuable tool for you as a Python developer. You can extract specific values or ranges of values using indices or slices. You may encounter the TypeError telling you that the index of the list must be integers or slices but not strings. In this part...