SHOW:
|
|
- or go back to the newest paste.
| 1 | from sklearn import datasets, linear_model | |
| 2 | from sklearn.metrics import r2_score, mean_squared_error | |
| 3 | from sklearn.preprocessing import PolynomialFeatures | |
| 4 | from sklearn.linear_model import LinearRegression | |
| 5 | from sklearn.pipeline import Pipeline | |
| 6 | from sklearn.model_selection import cross_val_score | |
| 7 | import numpy as np | |
| 8 | import pandas as pd | |
| 9 | import matplotlib.pyplot as plt | |
| 10 | ||
| 11 | ## подкл выборку | |
| 12 | ||
| 13 | x_train = pd.read_table ("tic/ticdata2000.txt", header = None).iloc [0:4000, 0:85]
| |
| 14 | x_test = x_train.iloc[0:4000, 84] | |
| 15 | ||
| 16 | ||
| 17 | y_train = pd.read_table ("tic/ticeval2000.txt", header = None)
| |
| 18 | y_test = pd.read_table ("tic/tictgts2000.txt", header = None)
| |
| 19 | ||
| 20 | ||
| 21 | ## обучение выборки | |
| 22 | regression = linear_model.LinearRegression() | |
| 23 | regression.fit (x_train, y_train) | |
| 24 | ||
| 25 | ||
| 26 | train_predict = regression.predict (x_train) | |
| 27 | ||
| 28 | print('Коэффициенты: \n', regression.coef_)
| |
| 29 | print("Cреднеквадратичная ошибка: %.2f" % mean_squared_error(y_train, train_predict))
| |
| 30 | print('Оценка отклонения: %.2f' % r2_score(y_train, train_predict))
| |
| 31 | ||
| 32 | ## Проверка точности модели по тестовой выборке и запись в результирующий файл | |
| 33 | y_pr = pd.DataFrame(train_predict) | |
| 34 | y_test = y_test.reset_index(drop = True) | |
| 35 | res = pd.concat([y_pr, y_test], axis=1) | |
| 36 | - | res.to_csv("result.txt", index = False)
|
| 36 | + | res.to_csv("result.txt", index = False) |