Skip to content

Instantly share code, notes, and snippets.

View grohith327's full-sized avatar

Rohith Gandhi G grohith327

View GitHub Profile
import pandas as pd
df = pd.read_csv('/Users/rohith/Documents/Datasets/Iris_dataset/iris.csv')
df = df.drop(['Id'],axis=1)
target = df['Species']
s = set()
for val in target:
s.add(val)
s = list(s)
rows = list(range(100,150))
from sklearn.metrics import accuracy_score
from sklearn.linear_model import LogisticRegression
clf = LogisticRegression()
clf.fit(x_train,y_train)
y_pred = clf.predict(x_test)
print(accuracy_score(y_test,y_pred))
import matplotlib.pyplot as plt
cost_func = np.array(cost_func)
cost_func = cost_func.reshape(10000,1)
plt.plot(range(len(cost_func)),cost_func)
from sklearn.metrics import accuracy_score
test_x_1 = x_test[:,0]
test_x_2 = x_test[:,1]
test_x_3 = x_test[:,2]
test_x_4 = x_test[:,3]
test_x_1 = np.array(test_x_1)
test_x_2 = np.array(test_x_2)
test_x_3 = np.array(test_x_3)
## Logistic Regression
import numpy as np
def sigmoid(x):
return (1 / (1 + np.exp(-x)))
m = 90
alpha = 0.0001
theta_0 = np.zeros((m,1))
from sklearn.utils import shuffle
from sklearn.cross_validation import train_test_split
import numpy as np
X, Y = shuffle(X,Y)
x_train = []
y_train = []
x_test = []
y_test = []
import pandas as pd
df = pd.read_csv('/Users/rohith/Documents/Datasets/Iris_dataset/iris.csv') ## Load data
df = df.drop(['Id'],axis=1)
rows = list(range(100,150))
df = df.drop(df.index[rows]) ## Drop the rows with target values Iris-virginica
Y = []
target = df['Species']
for val in target:
if(val == 'Iris-setosa'):
import matplotlib.pyplot as plt
y_prediction = a_0 + a_1 * x_test
print('R2 Score:',r2_score(y_test,y_prediction))
y_plot = []
for i in range(100):
y_plot.append(a_0 + a_1 * i)
plt.figure(figsize=(10,10))
plt.scatter(x_test,y_test,color='red',label='GT')
## Linear Regression
import numpy as np
n = 700
alpha = 0.0001
a_0 = np.zeros((n,1))
a_1 = np.zeros((n,1))
epochs = 0
from sklearn.linear_model import LinearRegression
from sklearn.metrics import r2_score
clf = LinearRegression(normalize=True)
clf.fit(x_train,y_train)
y_pred = clf.predict(x_test)
print(r2_score(y_test,y_pred))