Skip to content

Instantly share code, notes, and snippets.

View jainanchit51's full-sized avatar

Anchit Jain jainanchit51

View GitHub Profile
import pandas as pd
dataframe = pd.read_csv(‘breast-cancer-wisconsin.csv’, engine=’python’)
dataframe = dataframe.drop([‘bare_nucleoli’], axis=1)
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()
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)
#handling na
for label in ['clump_thickness','size_uniformity','shape_uniformity','marginal_adhesion']:
dataframe[label] = dataframe[label].fillna(method='ffill')
import pandas as pd
import numpy as np
# reading data
dataframe = pd.read_csv('home.txt',names=["size","bedroom","price"])
# normalizing data
size bedroom price
0 2104 3 399900
1 1600 3 329900
2 2400 3 369000
3 1416 2 232000
4 3000 4 539900
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
def train(self,learning_rate,iter):
alpha = learning_rate
iterations = range(0,iter)
# here x is columns
X = self.x_input
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))
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)