20 lines
898 B
Python
20 lines
898 B
Python
|
from sklearn.metrics import mean_absolute_percentage_error
|
||
|
from sklearn.model_selection import train_test_split
|
||
|
from sklearn.preprocessing import PolynomialFeatures
|
||
|
from sklearn.linear_model import LinearRegression
|
||
|
from sklearn.pipeline import Pipeline
|
||
|
import pandas as pd
|
||
|
|
||
|
data = pd.read_csv('boston.csv')
|
||
|
X = (data[['CRIM', 'RM', 'RAD']])
|
||
|
y = data['MEDV']
|
||
|
|
||
|
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
|
||
|
lin = LinearRegression()
|
||
|
polynomial_features = PolynomialFeatures(degree=1)
|
||
|
pipeline = Pipeline([("Linear", polynomial_features), ("linear_regression", lin)])
|
||
|
pipeline.fit(X_train, y_train)
|
||
|
y_predict = lin.predict(polynomial_features.fit_transform(X_test))
|
||
|
print('Предсказание: ', y_predict)
|
||
|
print('Оценка качества:', pipeline.score(X_test, y_test))
|
||
|
print('Ошибка:', mean_absolute_percentage_error(y_test, y_predict))
|