This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
dataframe = pd.read_csv(‘breast-cancer-wisconsin.csv’, engine=’python’) | |
dataframe = dataframe.drop([‘bare_nucleoli’], axis=1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import seaborn as sns | |
import matplotlib.pyplot as plt | |
sns.set(style=’ticks’, color_codes=True) | |
plt.figure(figsize=(14, 12)) | |
sns.heatmap(dataframe.astype(float).corr(), linewidths=0.1, square=True, linecolor=’white’, annot=True) | |
plt.show() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fig = plt.figure() | |
ax = sns.countplot(x=’bland_chromatin’, hue=’class’, data=dataframe) | |
ax.set(xlabel=’Bland Chromatin’, ylabel=’No of cases’) | |
fig.suptitle(“Bland Chromatin w.r.t. Class”, y=0.96) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#handling na | |
for label in ['clump_thickness','size_uniformity','shape_uniformity','marginal_adhesion']: | |
dataframe[label] = dataframe[label].fillna(method='ffill') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
import numpy as np | |
# reading data | |
dataframe = pd.read_csv('home.txt',names=["size","bedroom","price"]) | |
# normalizing data |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
size bedroom price | |
0 2104 3 399900 | |
1 1600 3 329900 | |
2 2400 3 369000 | |
3 1416 2 232000 | |
4 3000 4 539900 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
size bedroom price | |
0 0.130010 -0.223675 0.475747 | |
1 -0.504190 -0.223675 -0.084074 | |
2 0.502476 -0.223675 0.228626 | |
3 -0.735723 -1.537767 -0.867025 | |
4 1.257476 1.090417 1.595389 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def train(self,learning_rate,iter): | |
alpha = learning_rate | |
iterations = range(0,iter) | |
# here x is columns | |
X = self.x_input |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def cost_calculation(self,X,y,theta): | |
inner = np.power(((X @ theta.T) - y), 2) # @ means matrix multiplication of arrays. If we want to use * for multiplication we will have to convert all arrays to matrices | |
return np.sum(inner) / (2 * len(X)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def _gradient_descent(self,X, y, theta, alpha, iterations): | |
for i in (iterations): | |
theta = theta - (alpha/len(X)) * np.sum((X @ theta.T - y) * X, axis=0) | |
cost = self.cost_calculation(X, y, theta) |
OlderNewer