<jupyter_start><jupyter_text>데이터 로딩<jupyter_code>import pandas as pd
pd.read_csv('./auto-mpg.csv', header=None)
df = pd.read_csv('./auto-mpg.csv', header=None)
df.columns = ['mpg','cylinders','displacement','horsepower','weight',
              'acceleration','model year','origin','name']
df.info()
df.describe(include='all')<jupyter_output><empty_output><jupyter_text>replace<jupyter_code>df[['horsepower','name']].describe(include='all')
df['horsepower'].value_counts()
# df['horsepower'].astype('float64')
df['horsepower'].unique()
df['horsepower'].replace(to_replace='?', value=None, inplace=False)
df_horsepower = df['horsepower'].replace(to_replace='?', value=None, inplace=False)
df_horsepower.unique()
type(df['horsepower'])
type(df_horsepower)
df_horsepower = df_horsepower.astype('float')
df_horsepower.mean()
df['horsepower'] = df_horsepower.fillna(104)
df.info()
df['name'].unique()
df.head()<jupyter_output><empty_output><jupyter_text>분류와 연속컬럼 구분<jupyter_code>df.head(8)<jupyter_output><empty_output><jupyter_text>check columns- 연속형 : displacement, horsepower, weight, acceleration, mpg- 분류형 : model year, name, cylinders, origin- 중립형 :<jupyter_code>df['name'].value_counts()
# 카테고리에 너무 적어서 교육의 의미가 없음
df['mpg'].describe()
df['mpg'].value_counts()
df['cylinders'].describe()
df['cylinders'].value_counts()
df['origin'].value_counts()<jupyter_output><empty_output><jupyter_text>정규화 단계<jupyter_code>Y = df['mpg']
X_continus = df[['displacement','horsepower', 'weight','acceleration']]
X_category = df[['model year','cylinders','origin']]
from sklearn import preprocessing
scaler = preprocessing.StandardScaler()
type(scaler)
scaler.fit(X_continus)
X = scaler.transform(X_continus)
from sklearn.linear_model import LinearRegression
lr = LinearRegression()
type(lr)
lr.fit(X,Y)
lr.score(X_continus,Y)
df.head(1)<jupyter_output><empty_output><jupyter_text>X_continus = df[['displacement','horsepower', 'weight','acceleration']]순서에 맞추어 입력하여야 함<jupyter_code>lr.predict([[307.0, 130.0, 3504.0, 12.0]])
scaler.transform([[307.0, 130.0, 3504.0, 12.0]])
x_customer = scaler.transform([[307.0, 130.0, 3504.0, 12.0]])
x_customer.shape
lr.predict(x_customer)
# Y를 예측하는 것<jupyter_output><empty_output><jupyter_text>pickle<jupyter_code>import pickle
pickle.dump(lr, open('./autompg_lr.pkl', 'wb'))
!ls -l ./saves/autompg_lr.pkl
pickle.load(open('./saves/autompg_lr.pkl', 'rb'))

pickle.dump(scaler, open('./autompg_standardscaler.pkl', 'wb'))<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.18874038072093965, 'fraction_numerical': 0.02227622519238558, 'mean_word_length': 9.378151260504202, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 29, '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': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '240995', 'license': 'Apache-2.0', 'n_tokens_mistral': 1076, 'n_tokens_neox': 1059, 'n_words': 127, 'path': 'autompg_linearregression.ipynb', 'repo_name': 'creamcheesesteak/test_visualization', 'size': '2469'}