Python for Machine Learning

Pickle files (.pkl) are used to store the serialized form of Python objects. This means objects like list, set, tuple, dict, etc. are converted to a character stream before being stored on the disk. This allows you to continue working with the objects later on. These are particularly useful when you have trained your machine learning model and want to save them to make predictions later on.

So, if you serialized the files before saving them, you need to de-serialize them before you use them in your Python programs. This is done using the pickle.load() function in the pickle module. But when you open the pickle file with Python’s open() function, you need to provide the ‘rb’ parameter to read the binary file.

import pickle

with open('./Importing files/sample_pickle.pkl','rb') as file:
    data = pickle.load(file)

# pickle data
print(type(data))

df_pkl = pd.DataFrame(data)
df_pkl

Sir,
Can I use pd.read_pkl?
I have used pickle.load but not the aforementioned one. I tried to use it but got error message. It would be great if you could help me.
Thanking you,
Yours respectfully,
Indraayudh Talukdar

I just completed all the course material for Python for Machine Learning but then im not being able to access my qizz, which also donot allow to claim my certificate. Can somebody please help me.!

1 Like

Please check if you have watched all the videos completely (till the tick mark comes) in the course or not. The quiz will only unlock once you watches all the videos in the course.

Can anybody help me with knn?

1 Like

How to use not equal operator in python?

What do you mean by python scripting? What is a script and a module in python?

Python has two options for not equal operators:

  1. “!=”
  2. “<>”

!=( not equal operator ): This operator returns boolean values like

  • If the values of two operands are not equal, then the condition becomes true…
  • (a != b) is true.

“<>”: If values of two operands are not equal, then the condition becomes true.

  • If values of two operands are not equal, then the condition becomes true.
  • (a != b) is true.

string = ‘apple’
if string == ‘apple’: # equal
print (“matched”)
elif str != ‘apple’: # not equal
print (“not matched”)

A script is basically used to automate certain tasks in a program and a scripting language is a programming language that uses an Interpreter to translate its source code.

The interpreter reads and executes each line of code one at a time,

In the language Python uses an interpreter to translate and run the code. So for that Python called as a scripting language

How to install tensorflow in anaconda?

  1. Download and install Anaconda or the smaller Miniconda.
  2. On Windows open the Start menu and open an Anaconda Command Prompt.
  3. Choose an alias name for your TensorFlow environment, such as “tf”.
  4. conda create -n tf tensorflow
  5. conda activate tf
  6. Or, to install the current release of GPU TensorFlow on Linux or Windows:
  7. conda create -n tf-gpu tensorflow-gpu

how to find files and skip directories in os.listdir?

If you want to filter the directories then:
os.listdir() —> will return the list of all names in a given path.
You can use os.path.isdir() for this:

basic_path = ‘/path/to/directory’
for name in os.listdir(basic_path):
paths = os.path.join(basic_path, name)
if os.path.isdir(paths):
# skip directories
continue
os.walk()–> this function does the same work under the hood and unless you want to recurse down subdirectories

Can you help me with this error: ModuleNotFoundError: No module named ‘cv2’ ?

This error may come if you do not have an opencv installed module in your system.

check the module is available or not.

$ pip list or conda list

If it is not available, then install Opencv

$ pip install opencv-python or conda install opencv-python

But before that, Install numpy module

$ pip install numpy

What is the difference between list and tuple?

1.The main difference between lists and tuples is: lists are mutable whereas tuples are immutable.
2.Implication of iterations is Time-consuming for list
3. Implication of iterations is comparatively Faster for Tuple
4. The list is better for performing operations, such as insertion and deletion.
5.Tuple data type is appropriate for accessing the elements
6. Lists consume more memory
7.Tuple consume less memory as compared to the list

Why is there no do while loop in python?

What is the difference between Python’s list methods append and extend?

There is no do while loop present in python because there is no proper way to define the loop. do…while statement has been rejected because it doesn’t fit in the general format of indented block statement: indented block used by every other Python compound statement.
while True:

statement(s)

if not condition:
Break