Scikit-Learn


Output  Accuracy: 0.9833333333333333  Predictions: ['versicolor', 'virginica']  Model Persistence



Yüklə 1,92 Mb.
Pdf görüntüsü
səhifə15/124
tarix23.02.2023
ölçüsü1,92 Mb.
#101394
1   ...   11   12   13   14   15   16   17   18   ...   124
sklearn

Output 
Accuracy: 0.9833333333333333 
Predictions: ['versicolor', 'virginica'] 
Model Persistence 
Once you train the model, it is desirable that the model should be persist for future use so 
that we do not need to retrain it again and again. It can be done with the help of 
dump
and 
load
features of 
joblib
package.
Consider the example below in which we will be saving the above trained model 
(classifier_knn) for future use: 
from sklearn.externals import joblib 
joblib.dump(classifier_knn, 'iris_classifier_knn.joblib') 
The above code will save the model into file named 
iris_classifier_knn.joblib
. Now, the 
object can be reloaded from the file with the help of following code: 
joblib.load('iris_classifier_knn.joblib') 
 


Scikit-Learn

Preprocessing the Data 
As we are dealing with lots of data and that data is in raw form, before inputting that data 
to machine learning algorithms, we need to convert it into meaningful data. This process 
is called preprocessing the data. Scikit-learn has package named
 preprocessing 
for this 
purpose. The 
preprocessing 
package has the following techniques: 
Binarisation 
This preprocessing technique is used when we need to convert our numerical values into 
Boolean values.
Example 
import numpy as np 
from sklearn import preprocessing
Input_data = np.array([2.1, -1.9, 5.5], 
[-1.5, 2.4, 3.5], 
[0.5, -7.9, 5.6], 
[5.9, 2.3, -5.8]])
data_binarized = preprocessing.Binarizer(threshold=0.5).transform(input_data) 
print("\nBinarized data:\n", data_binarized) 
In the above example, we used 
threshold value =

Yüklə 1,92 Mb.

Dostları ilə paylaş:
1   ...   11   12   13   14   15   16   17   18   ...   124




Verilənlər bazası müəlliflik hüququ ilə müdafiə olunur ©genderi.org 2024
rəhbərliyinə müraciət

    Ana səhifə