Scikit-Learn


sklearn.random_projection



Yüklə 1,92 Mb.
Pdf görüntüsü
səhifə26/124
tarix23.02.2023
ölçüsü1,92 Mb.
#101394
1   ...   22   23   24   25   26   27   28   29   ...   124
sklearn

sklearn.random_projection
module used to reduce the dimensionality of the data, will 
explain it: 
import numpy as np 
5.
 
Scikit-Learn — Conventions


Scikit-Learn
27 
from sklearn import random_projection 
rannge = np.random.RandomState(0) 
X = range.rand(10,2000) 
X = np.array(X, dtype = 'float32') 
X.dtype 
Transformer_data = random_projection.GaussianRandomProjection() 
X_new = transformer.fit_transform(X) 
X_new.dtype 
Output 
dtype('float32') 
dtype('float64')
In the above example, we can see that X is 
float32
which is cast to 
float64
by 
fit_transform(X).
Refitting & Updating Parameters 
Hyper-parameters of an estimator can be updated and refitted after it has been 
constructed via the 
set_params()
method. Let’s see the following example to understand 
it: 
import numpy as np 
from sklearn.datasets import load_iris 
from sklearn.svm import SVC 
X, y = load_iris(return_X_y=True) 
clf = SVC() 
clf.set_params(kernel='linear').fit(X, y)
clf.predict(X[:5]) 
 
Output 


Scikit-Learn
28 
array([0, 0, 0, 0, 0]) 
Once the estimator has been constructed, above code will change the default kernel 
rbf
to linear via 
SVC.set_params().
Now, the following code will change back the kernel to 
rbf
to refit the estimator and to 
make a second prediction. 
clf.set_params(kernel='rbf', gamma='scale').fit(X, y)
clf.predict(X[:5]) 
Output 
array([0, 0, 0, 0, 0]) 
Complete code 
The following is the complete executable program: 
import numpy as np 
from sklearn.datasets import load_iris 
from sklearn.svm import SVC 
X, y = load_iris(return_X_y=True) 
clf = SVC() 
clf.set_params(kernel='linear').fit(X, y)
clf.predict(X[:5]) 
clf.set_params(kernel='rbf', gamma='scale').fit(X, y)
clf.predict(X[:5]) 

Yüklə 1,92 Mb.

Dostları ilə paylaş:
1   ...   22   23   24   25   26   27   28   29   ...   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ə