In [80]:
import pandas as pd
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LinearRegression
import numpy as np
Download Dataset: movies_multilinear_reg.csv
In [81]:
movies = pd.read_csv('datasets/movies_multilinear_reg.csv')
In [82]:
type(movies)
Out[82]:
In [83]:
movies.head(10)
Out[83]:
In [84]:
movies.shape
Out[84]:
In [85]:
filmes_independente = movies[movies.columns[2:17]]
In [86]:
type(filmes_independente)
Out[86]:
In [87]:
filmes_dependente = movies[movies.columns[17:]]
In [88]:
type(filmes_dependente)
Out[88]:
In [89]:
train, test, train_bilheteria, test_bilheteria = train_test_split(filmes_independente, filmes_dependente)
In [90]:
train.head()
Out[90]:
In [91]:
train.shape[0]
Out[91]:
In [92]:
test.shape[0]
Out[92]:
In [93]:
modelo = LinearRegression()
modelo.fit(train,train_bilheteria)
Out[93]:
In [94]:
modelo.predict([[0,0,0,0,0,0,0,1,1,1,1,0,1,103.4683096,11.04821649]])
Out[94]:
In [95]:
modelo.score(train, train_bilheteria)
Out[95]:
In [96]:
modelo.coef_
Out[96]:
In [97]:
modelo.intercept_
Out[97]:
In [98]:
modelo.score(test, test_bilheteria)
Out[98]:
In [99]:
zootopia = [0,0,0,0,0,0,0,1,1,1,1,0,1,110,27.74456356]
modelo.predict([zootopia])
Out[99]:
In [100]:
train, test, train_bilheteria, test_bilheteria = train_test_split(filmes_independente, filmes_dependente, test_size=0.3)
In [101]:
modelo_30 = LinearRegression()
modelo_30.fit(train,train_bilheteria)
Out[101]:
In [102]:
modelo_30.score(test, test_bilheteria)
Out[102]:
In [103]:
zootopia = [0,0,0,0,0,0,0,0,1,1,1,0,1,145.5170642,3.451632127]
modelo.predict([zootopia])
Out[103]:
In [104]:
planeta_macaco = [0,1,0,0,0,0,0,0,0,0,0,0,0,150,5]
modelo.predict([planeta_macaco])
Out[104]: