<jupyter_start><jupyter_text><jupyter_code>import numpy as np
import io
import pandas as pd
import sklearn.model_selection

from google.colab import files
from pandas import Series,DataFrame
from sklearn import linear_model
from sklearn import preprocessing
from sklearn.metrics import mean_squared_error

#1.訓練データの読み込み
uploaded = files.upload()
train_data = pd.read_csv(io.StringIO(uploaded['reg_train.tsv'].decode('utf-8')), delimiter='\t')

#2.特徴量の抽出（「NaN」に中央値を当てはめる）
imp = preprocessing.Imputer(missing_values='NaN', strategy='median')
X = DataFrame(imp.fit_transform(train_data.drop(["id", "mpg", "car name"], 1)))

#3.標準化
scaler = preprocessing.StandardScaler()
X = scaler.fit_transform(X)
Y = train_data['mpg']

#4.訓練データと検証データの仕分け
X_train, X_test, Y_train, Y_test = sklearn.model_selection.train_test_split(X,Y)

#5.分析(線形回帰)
linear_regression = linear_model.LinearRegression()
linear_regression.fit(X_train,Y_train)

#6.精度検証
predict_output = DataFrame(linear_regression.predict(X_test), Y_test)
print("予測結果:")
print(predict_output)
print("誤差の平均値:")
print(np.sqrt(mean_squared_error(predict_output,Y_test)))<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12860892388451445, 'fraction_numerical': 0.00699912510936133, 'mean_word_length': 8.777777777777779, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '478454', 'license': 'RSA-MD', 'n_tokens_mistral': 478, 'n_tokens_neox': 484, 'n_words': 73, 'path': 'linear_regression.ipynb', 'repo_name': 'Asahi300/aisample', 'size': '1143'}