<jupyter_start><jupyter_text>Multiple Linear Regression (다중 선형 회귀) - In this practice, we are going to find regression model to predict *profit* of the startup company with various dependent varialbes such as R&D spend and Marketting spend.- For simplicity, we will not consider *categorical value* such as 'state'.  Importing the libraries<jupyter_code>import numpy as np
import matplotlib.pyplot as plt
import pandas as pd<jupyter_output><empty_output><jupyter_text>Importing the dataset<jupyter_code>dataset = pd.read_csv('50_Startups.csv')
dataset # 데이터 정보확인<jupyter_output><empty_output><jupyter_text>Sklearn's regression models expect the shape of X and y as  - X : [number_of_data, number_of_features ]- y : [number_of_data, number_of_features]Therefore, we need to convert dataframe's result to correct numpy object<jupyter_code>dataset.columns
dataset[ ['R&D Spend', 'Administration', 'Marketing Spend'] ]
X_input = dataset[ ['R&D Spend', 'Administration', 'Marketing Spend'] ] # do not use 'state'
y_input = dataset[ 'Profit' ]
X_input.values
y_input
X = X_input.values
y = y_input.values
print("Shape of X : ", X.shape)
print("Shape of y : ", y.shape)<jupyter_output>Shape of X :  (50, 3)
Shape of y :  (50,)<jupyter_text>Splitting the dataset into the Training set and Test set<jupyter_code>from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.2, random_state = 0)
X_test.shape<jupyter_output><empty_output><jupyter_text>Training the Multiple Linear Regression model on the Training set<jupyter_code>from sklearn.linear_model import LinearRegression
regressor = LinearRegression()
regressor.fit(X_train, y_train)<jupyter_output><empty_output><jupyter_text>Predicting the Test set results<jupyter_code>y_pred = regressor.predict(X_test)
np.set_printoptions(precision=2)
print(np.concatenate((y_pred.reshape(len(y_pred),1), y_test.reshape(len(y_test),1)),1))<jupyter_output>[[103901.9  103282.38]
 [132763.06 144259.4 ]
 [133567.9  146121.95]
 [ 72911.79  77798.83]
 [179627.93 191050.39]
 [115166.65 105008.31]
 [ 67113.58  81229.06]
 [ 98154.81  97483.56]
 [114756.12 110352.25]
 [169064.01 166187.94]]<jupyter_text>To check the result easily, convert the reference and the predict to dataframe.<jupyter_code>data = { 'ref': y_test, 'pred':y_pred, 'diff':np.abs( (y_test - y_pred) ) }
df = pd.DataFrame(data)
df<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11257731958762887, 'fraction_numerical': 0.06804123711340206, 'mean_word_length': 6.510835913312693, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 27, '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': '499244', 'license': 'MIT', 'n_tokens_mistral': 1005, 'n_tokens_neox': 900, 'n_words': 220, 'path': 'DeepLearning/1. regression/multiple_linear_regression.ipynb', 'repo_name': 'KwanHoo/coding-playgroung', 'size': '2425'}