DL Lab 5
DL Lab 5
data = pd.read_csv(r"C:\Users\aksha\Downloads\suv_data.csv")
print(data.head())
X = data[['Age', 'EstimatedSalary']].values
y = data['Purchased'].values
scaler = StandardScaler()
X_train = scaler.fit_transform(X_train)
X_test = scaler.transform(X_test)
def sigmoid(z):
return 1 / (1 + np.exp(-z))
class LogisticRegression:
def __init__(self, learning_rate=0.01, num_iterations=1000):
self.learning_rate = learning_rate
self.num_iterations = num_iterations
self.weights = None
self.bias = None
for _ in range(self.num_iterations):
linear_model = np.dot(X, self.weights) + self.bias
y_predicted = sigmoid(linear_model)
self.weights -= self.learning_rate * dw
self.bias -= self.learning_rate * db
for i, j in enumerate(np.unique(y_set)):
plt.scatter(X_set[y_set == j, 0], X_set[y_set == j, 1],
c=[(0, 0, 1), (0, 1, 0)][i], label=j, edgecolor='black') #
C:\Users\aksha\AppData\Local\Temp\ipykernel_16312\520669100.py:16: UserWarning: *
c* argument looks like a single numeric RGB or RGBA sequence, which should be avo
ided as value-mapping will have precedence in case its length matches with *x* &
*y*. Please use the *color* keyword-argument or provide a 2D array with a single
row if you intend to specify the same RGB or RGBA value for all points.
plt.scatter(X_set[y_set == j, 0], X_set[y_set == j, 1],
sklearn_model = SklearnLogisticRegression()
sklearn_model.fit(X_train, y_train)
sklearn_y_pred = sklearn_model.predict(X_test)