-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIO_Project.py
More file actions
113 lines (105 loc) · 3.1 KB
/
Copy pathIO_Project.py
File metadata and controls
113 lines (105 loc) · 3.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
df = pd.read_csv('/content/drive/MyDrive/Movie_classification.csv')
df.head()
df.shape
df.columns
df = df.drop(['Start_Tech_Oscar'], axis=1)
df
df.isnull().sum()
df1 = df.fillna(method = 'bfill')
df1.isnull().sum()
from sklearn.preprocessing import LabelEncoder
encoder = LabelEncoder()
encoder.fit(df['3D_available'])
df['3D_available'] = encoder.transform(df['3D_available'])
encoder = LabelEncoder()
encoder.fit(df['Genre'])
df['Genre'] = encoder.transform(df['Genre'])
sns.boxplot(x='Marketing expense', data = df1)
sns.boxplot(x='Production expense', data = df1)
sns.boxplot(x='Multiplex coverage', data = df1)
sns.boxplot(x='Budget', data = df1)
sns.boxplot(x='Movie_length', data = df1)
sns.boxplot(x='Lead_ Actor_Rating', data = df1)
sns.boxplot(x='Lead_Actress_rating', data = df1)
sns.boxplot(x='Director_rating', data = df1)
sns.boxplot(x='Producer_rating', data = df1)
sns.boxplot(x='Critic_rating', data = df1)
sns.boxplot(x='Trailer_views', data = df1)
sns.boxplot(x='Time_taken', data = df1)
sns.boxplot(x='Twitter_hastags', data = df1)
sns.boxplot(x='Avg_age_actors', data = df1)
sns.boxplot(x='Num_multiplex', data = df1)
q1,q3 = np.percentile(df1['Marketing expense'],[25,75])
q1,q3
iqr = q3 - q1
iqr
lb = q1 - (1.5)*iqr
ub = q3 + (1.5)*iqr
lb, ub
no_outliers = []
for i in df1['Marketing expense']:
if i<=lb or i>=ub:
pass
else:
no_outliers.append(i)
sns.boxplot(no_outliers)
q1,q3 = np.percentile(df1['Time_taken'],[25,75])
q1,q3
iqr = q3 - q1
iqr
lb = q1 - (1.5)*iqr
ub = q3 + (1.5)*iqr
lb, ub
no_outliers = []
for i in df1['Time_taken']:
if i<=lb or i>=ub:
pass
else:
no_outliers.append(i)
sns.boxplot(no_outliers)
q1,q3 = np.percentile(df1['Trailer_views'],[25,75])
q1,q3
iqr = q3 - q1
iqr
lb = q1 - (1.5)*iqr
ub = q3 + (1.5)*iqr
lb, ub
no_outliers = []
for i in df1['Trailer_views']:
if i<=lb or i>=ub:
pass
else:
no_outliers.append(i)
sns.boxplot(no_outliers)
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LinearRegression
from sklearn.tree import DecisionTreeRegressor
from sklearn.ensemble import RandomForestRegressor
from sklearn.metrics import r2_score, mean_absolute_error
from sklearn.preprocessing import LabelEncoder
from sklearn.model_selection import GridSearchCV
X = df1.drop(['Collection'], axis=1)
y = df1['Collection']
encoder = LabelEncoder()
encoder.fit(df1['3D_available'])
df1['3D_available'] = encoder.transform(df1['3D_available'])
encoder = LabelEncoder()
encoder.fit(df1['Genre'])
df1['Genre'] = encoder.transform(df1['Genre'])
X_train, X_test, y_train, y_test = train_test_split(X,y,test_size=0.2)
lr=LinearRegression()
lr.fit(X_train,y_train)
y_pred_lr = lr.predict(X_test)
r2_score(y_pred_lr,y_test)
dtr= DecisionTreeRegressor()
dtr.fit(X_train,y_train)
y_pred_dtr = dtr.predict(X_test)
r2_score(y_pred_dtr,y_test)
rfr = RandomForestRegressor()
rfr.fit(X_train,y_train)
y_pred_rfr = rfr.predict(X_test)
r2_score(y_pred_rfr,y_test)