Professional Documents
Culture Documents
Advertising PDF
Advertising PDF
In [2]:
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
In [3]:
In [4]:
%matplotlib inline
In [6]:
file = r'C:\Users\hp\Desktop\advertising.csv'
data = pd.read_csv(file)
In [7]:
data.head()
Out[7]:
In [20]:
In [11]:
data.info()
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 200 entries, 0 to 199
Data columns (total 5 columns):
Unnamed: 0 200 non-null int64
TV 200 non-null float64
radio 200 non-null float64
newspaper 200 non-null float64
sales 200 non-null float64
dtypes: float64(4), int64(1)
memory usage: 7.9 KB
http://localhost:8888/nbconvert/html/Advertising.ipynb?download=false 1/12
3/23/2019 Advertising
In [21]:
data.describe()
Out[21]:
In [22]:
Out[22]:
<matplotlib.axes._subplots.AxesSubplot at 0x1ed5ba54630>
http://localhost:8888/nbconvert/html/Advertising.ipynb?download=false 2/12
3/23/2019 Advertising
In [30]:
sns.distplot(data['sales'],hist = True)
Out[30]:
<matplotlib.axes._subplots.AxesSubplot at 0x1ed5bf0be10>
http://localhost:8888/nbconvert/html/Advertising.ipynb?download=false 3/12
3/23/2019 Advertising
In [29]:
Out[29]:
<seaborn.axisgrid.FacetGrid at 0x1ed5beaa7f0>
http://localhost:8888/nbconvert/html/Advertising.ipynb?download=false 4/12
3/23/2019 Advertising
In [35]:
sns.pairplot(data)
http://localhost:8888/nbconvert/html/Advertising.ipynb?download=false 5/12
3/23/2019 Advertising
Out[35]:
<seaborn.axisgrid.PairGrid at 0x1ed5f436978>
http://localhost:8888/nbconvert/html/Advertising.ipynb?download=false 6/12
3/23/2019 Advertising
http://localhost:8888/nbconvert/html/Advertising.ipynb?download=false 7/12
3/23/2019 Advertising
In [36]:
data.head()
Out[36]:
In [39]:
X = data.drop(['sales'],axis = 1)
y = data['sales']
In [40]:
In [41]:
In [42]:
In [44]:
logmodel = LogisticRegression()
In [56]:
lab_enc = preprocessing.LabelEncoder()
encoded = lab_enc.fit_transform(y_train)
In [66]:
lab_enc = preprocessing.LabelEncoder()
encoded2 = lab_enc.fit_transform(y_test)
http://localhost:8888/nbconvert/html/Advertising.ipynb?download=false 8/12
3/23/2019 Advertising
In [60]:
logmodel.fit(X_train,encoded)
C:\Users\hp\Anaconda3\lib\site-packages\sklearn\linear_model\logistic.py:4
33: FutureWarning: Default solver will be changed to 'lbfgs' in 0.22. Spec
ify a solver to silence this warning.
FutureWarning)
C:\Users\hp\Anaconda3\lib\site-packages\sklearn\linear_model\logistic.py:4
60: FutureWarning: Default multi_class will be changed to 'auto' in 0.22.
Specify the multi_class option to silence this warning.
"this warning.", FutureWarning)
Out[60]:
In [61]:
predictions = logmodel.predict(X_test)
http://localhost:8888/nbconvert/html/Advertising.ipynb?download=false 9/12
3/23/2019 Advertising
In [69]:
http://localhost:8888/nbconvert/html/Advertising.ipynb?download=false 10/12
3/23/2019 Advertising
http://localhost:8888/nbconvert/html/Advertising.ipynb?download=false 11/12
3/23/2019 Advertising
C:\Users\hp\Anaconda3\lib\site-packages\sklearn\metrics\classification.py:
1143: UndefinedMetricWarning: Precision and F-score are ill-defined and be
ing set to 0.0 in labels with no predicted samples.
'precision', 'predicted', average, warn_for)
C:\Users\hp\Anaconda3\lib\site-packages\sklearn\metrics\classification.py:
1145: UndefinedMetricWarning: Recall and F-score are ill-defined and being
set to 0.0 in labels with no true samples.
'recall', 'true', average, warn_for)
C:\Users\hp\Anaconda3\lib\site-packages\sklearn\metrics\classification.py:
1143: UndefinedMetricWarning: Precision and F-score are ill-defined and be
ing set to 0.0 in labels with no predicted samples.
'precision', 'predicted', average, warn_for)
C:\Users\hp\Anaconda3\lib\site-packages\sklearn\metrics\classification.py:
1145: UndefinedMetricWarning: Recall and F-score are ill-defined and being
set to 0.0 in labels with no true samples.
'recall', 'true', average, warn_for)
C:\Users\hp\Anaconda3\lib\site-packages\sklearn\metrics\classification.py:
1143: UndefinedMetricWarning: Precision and F-score are ill-defined and be
ing set to 0.0 in labels with no predicted samples.
'precision', 'predicted', average, warn_for)
C:\Users\hp\Anaconda3\lib\site-packages\sklearn\metrics\classification.py:
1145: UndefinedMetricWarning: Recall and F-score are ill-defined and being
set to 0.0 in labels with no true samples.
'recall', 'true', average, warn_for)
In [ ]:
http://localhost:8888/nbconvert/html/Advertising.ipynb?download=false 12/12