"""
The dataset we have here belongs to 50 startups companies. Companies are going to be in a venture capitalist fund 
challenge. We have 5 columns in dataset (R&D Spend,Administration, Marketing Spend, Profit & State). 
In data we have information regarding how much the company in financial year has spend on different departments 
with respective profit and state in which companies are operational.
The challenge here is that, all data is totally anonomous so we do not know the companies but we have to analyze 
these 50 companies and create model that will help venture capitalists in which type of company they should 
invest to maximize the profit.

Features: R&D Spend, Administration, Marketing Spend, State
Target Variable: Profit
"""
"""
Importing the Libraries
"""
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
"""
Importing the Dataset
"""
dataset = pd.read_csv("../input/50-startup-companies/50_Startups.csv")
dataset.head()
"""
Splitting data into (X contains Features and y contains dependent variable)
"""
X = dataset.iloc[:, :-1].values
y = dataset.iloc[:, -1].values
print(X)
print(y)
"""
Encoding Categorical Data
"""
"""
As you can see that there are multiple descriptive values appearing in State Column. we have to apply **OneHotEncoding**, that will
convert descriptve values of State Column into Binary values and split into 3 different columns.
"""
#This code will change the categorical column into binary column
from sklearn.compose import ColumnTransformer
from sklearn.preprocessing import OneHotEncoder
ct = ColumnTransformer(transformers=[('encoder', OneHotEncoder(), [3])], remainder='passthrough')
X = np.array(ct.fit_transform(X))
print(X)
"""
Please note that, there is no need to apply **Feature Scaling** here because in the Multi Linear Regression we have coefficients that will multiply with each feature, therefore it does not matter that some features
have higher values than others because coefficients will put every feature on scale.
"""
"""
Splitting the dataset into Training set and Test set
"""
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)
from sklearn.linear_model import LinearRegression
regressor = LinearRegression()
regressor.fit(X_train,y_train)
y_pred = regressor.predict(X_test)
np.set_printoptions(precision=2)#This is used to only get values in 2 decimals.
"""
Now we are going to vertically concatinate Predicted Results with Test Results
"""
print(np.concatenate((y_pred.reshape(len(y_pred),1), y_test.reshape(len(y_test),1)),1))
"""
We can clearly see two vectors above. The left one is predicted profits and right one is real
profits from test set. As you can see in results that most of the predicted values are very close when we compare them with real values on right side.
Now Lets evaluate the performance of our Model. There are multiple methods to evaluate model but we are going to use **RSquare** method for model evaluation.
"""
from sklearn.metrics import r2_score
r2_score(y_test, y_pred)
"""
As you can see above that our model accuracy is **93%** which is very good. So, that concludes the Basic implementation of **Multiple Linear Regression Model**. Please feel free to add in case i missed something and correct me if there is any mistake.
"""