Scikit-Learn



Yüklə 1,92 Mb.
Pdf görüntüsü
səhifə50/124
tarix23.02.2023
ölçüsü1,92 Mb.
#101394
1   ...   46   47   48   49   50   51   52   53   ...   124
sklearn

n_output_features _:
 int 
As name suggests, it gives the total number of 
polynomial output features.
Implementation Example 
Following Python script uses 
PolynomialFeatures
 
transformer to transform array of 8 
into shape (4,2): 
from sklearn.preprocessing import PolynomialFeatures 
import numpy as np 
Y = np.arange(8).reshape(4, 2) 
poly = PolynomialFeatures(degree=2) 
poly.fit_transform(Y) 
Output 
array([[ 1., 0., 1., 0., 0., 1.], 
[ 1., 2., 3., 4., 6., 9.], 
[ 1., 4., 5., 16., 20., 25.], 
[ 1., 6., 7., 36., 42., 49.]]) 
Streamlining using Pipeline tools 
The above sort of preprocessing i.e. transforming an input data matrix into a new data 
matrix of a given degree, can be streamlined with the 
Pipeline
tools, which are basically 
used to chain multiple estimators into one. 
Example 
The below python scripts using Scikit-learn’s Pipeline tools to streamline the preprocessing 
(will fit to an order-3 polynomial data). 
#First, import the necessary packages. 


Scikit-Learn
56 
 
from sklearn.preprocessing import PolynomialFeatures 
from sklearn.linear_model import LinearRegression 
from sklearn.pipeline import Pipeline 
import numpy as np 
 
#Next, create an object of Pipeline tool 
 
Stream_model = Pipeline([('poly', PolynomialFeatures(degree=3)),
('linear', LinearRegression(fit_intercept=False))]) 
 
#
Provide the size of array and order of polynomial data to fit the model. 
 
x = np.arange(5) 
y = 3 - 2 * x + x ** 2 - x ** 3 
Stream_model = model.fit(x[:, np.newaxis], y) 
#Calculate the input polynomial coefficients

Yüklə 1,92 Mb.

Dostları ilə paylaş:
1   ...   46   47   48   49   50   51   52   53   ...   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ə