0% found this document useful (0 votes)
35 views

Mlext

Uploaded by

21491a05w8
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
35 views

Mlext

Uploaded by

21491a05w8
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

EXP(3): EXP(6): EXP(9) logistic):

#Statistics Module: import numpy as np import numpy as np


import statistics as st import pandas as pd import matplotlib.pyplot as plt
data = [5, 4, 1, 3, 2, 4, 5, 4, 5, 6] import seaborn as sns import pandas as pd
print('Mean: ', st.mean(data)) import os import seaborn as sns
print('Median: ', st.median(data)) for dirname, _, filenames in from sklearn.model_selection import
print('Mode: ', st.mode(data)) os.walk('kaggle/input'): train_test_split
print('Variance: ', round(st.variance(data),2)) for filename in filenames: from sklearn.preprocessing import
print('Standard Deviation: ', print(os.path.join(dirname, filename)) StandardScaler
round(st.stdev(data),2)) import matplotlib.pyplot as plt from sklearn.linear_model import
#Math module: %matplotlib inline LogisticRegression
import math df = pd.read_csv('/content/minihomeprices.csv') from sklearn.metrics import confusion_matrix,
print("Exponential value: ", math.e) df.head() accuracy_score
print("Pi value: ",math.pi) df.info() dataset =
print("Infinite value: ", math.inf) df.describe().style.background_gradient(cmap=' pd.read_csv('/content/Social_Network_Ads.csv')
print("Not a number value: ", math.nan) CMRmap') print(dataset.columns)
print("Logarithmic: ", math.log(math.e)) df.isna().sum() X = dataset[['Age', 'EstimatedSalary']]
print("factorial of 5 is", math.factorial(5)) df['bedrooms'] = df['bedrooms'].fillna( y = dataset['Purchased']
print("GCD of 64 and 42 is", math.gcd(64,42)) df['bedrooms'].mean() ) X_train,X_test,y_train,y_test =
print("Floor of 5.67 is", math.floor(5.67)) df.head() train_test_split(X,y,test_size=0.25)
print("Ceil of 5.67 is", math.ceil(5.67)) plt.figure(figsize=(10, 7)) #feature scaling
#Numpy module plt.title("Bedroom wise price increase") sc = StandardScaler()
import numpy as np plt.xlabel("Bedrooms" ) X_train = sc.fit_transform(X_train)
#Creating arrays plt.ylabel('Price') X_test = sc.transform(X_test)
ar1d = np.arange(11,17) plt.show() classifier = LogisticRegression()
ar2d = np.arange(11,36).reshape(5,5) plt.figure(figsize=(10, 5)) classifier.fit(X_train, y_train)
print("1-D array is:") plt.title("Price vs Bedroom Scatter plot") y_pred = classifier.predict(X_test)
print(ar1d) plt.xlabel("House Bedrooms") print("Confusion Matrix")
print("2-D array is:") plt.ylabel("House Price") print(confusion_matrix(y_test, y_pred))
print(ar2d) plt.show() print("Accuracy Score",accuracy_score(y_test,
#Properties plt.figure(figsize=(10, 7)) y_pred))
print("ar1d shape, size, dimensions are", sns.lmplot(x='bedrooms', y='price', data=df); sns.regplot(x=X_test[:,:-1], y=y_test,
ar1d.shape, ar1d.size,ar1d.ndim) plt.title("Price and bedroom wise line plot") logistic=True)
print("ar2d shape, size, dimensions are", plt.show() sns.regplot(x=X_test[:,:-1], y=y_pred,
ar2d.shape, ar2d.size,ar2d.ndim) from sklearn.linear_model import logistic=True)
#indexing LinearRegression OUTPUT:
print("Indexing on ar1d:", ar1d[2],ar1d[-2]) mdl = LinearRegression() Index(['Age', 'EstimatedSalary', 'Purchased'],
print("Indexing on ar2d:", ar2d[2][1],ar2d[1][1]) X = df.drop(['price'], axis=1) dtype='object')
#slicing y = df['price'] Confusion Matrix
print("Slicing on ar1d:", ar1d[2:6]) df['bedrooms'] = df['bedrooms'].astype('int64') [[63 2]
print("Slicing on ar2d:") df.info() [11 24]]
print(ar2d[1:4,2:4]) print(X) Accuracy Score 0.87
#scipy Module print('-' * 25)
from scipy import constants print(y)
print(constants.pi) mdl.fit(X, y)
print(constants.giga) OUTPUT:
print(constants.mega) <class 'pandas.core.frame.DataFrame'>
print(constants.kilo) RangeIndex: 6 entries, 0 to 5
print(constants.gram) Data columns (total 4 columns):
print(constants.pound) # Column Non-Null Count Dtype
OUTPUT: --- ------ -------------- -----
Mean: 3.9 0 area 6 non-null int64
Median: 4.0 1 bedrooms 6 non-null int64
Mode: 5 2 age 6 non-null int64
Variance: 2.32 3 price 6 non-null int64
Standard Deviation: 1.52 dtypes: int64(4)
Exponential value: 2.718281828459045 memory usage: 320.0 bytes
Pi value: 3.141592653589793 area bedrooms age
Infinite value: inf 0 2600 3.0 20
Not a number value: nan 1 3000 4.0 15
Logarithmic: 1.0 2 3200 4.2 18
factorial of 5 is 120 3 3600 3.0 30
GCD of 64 and 42 is 2 4 4000 5.0 8
Floor of 5.67 is 5 5 4100 6.0 8
Ceil of 5.67 is 6 -------------------------
1-D array is: 0 550000
[11 12 13 14 15 16] 1 565000
2-D array is: 2 610000
[[11 12 13 14 15] 3 595000
[16 17 18 19 20] 4 760000
[21 22 23 24 25] 5 810000
[26 27 28 29 30] Name: price, dtype: int64
[31 32 33 34 35]]
ar1d shape, size, dimensions are (6,) 6 1
ar2d shape, size, dimensions are (5, 5) 25 2
Indexing on ar1d: 13 15
Indexing on ar2d: 22 17
Slicing on ar1d: [13 14 15 16]
Slicing on ar2d:
[[18 19]
[23 24]
[28 29]]
3.141592653589793
1000000000.0
1000000.0
1000.0
0.001
0.45359236999999997

You might also like