Challenge-Hardwork Pays off

I am getting negtive accuracy.Please help me

import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
dfx=pd.read_csv(‘Linear_X_Train.csv’)
dfy=pd.read_csv(‘Linear_Y_Train.csv’)
dfz=pd.read_csv(‘Linear_X_Test.csv’)
x=dfx.values
y=dfy.values
z=dfz.values
print(x.shape)
print(y.shape)
print(z.shape)
plt.scatter(x,y)
X=(x-x.mean())/x.std()
Y=y
Z=z
plt.scatter(X,Y)
plt.show()
plt.scatter(X,Y)
plt.show()
def hypothesis(x,theta):
return theta[0]+theta[1]*x

def error(X,Y,theta):
m=X.shape[0]
error=0

for i in range(m):
    hx=hypothesis(X[i],theta)
    error+=(hx-Y[i])**2
    
return error

def gradient(X,Y,theta):

grad=np.zeros((2,))
m=X.shape[0]

for i in range(m):
    hx=hypothesis(X[i],theta)
    grad[0]+=(hx-Y[i])
    grad[1]+=(hx-Y[i])*X[i]

return grad

#Algorithm
def gradientDescent(X,Y,learning_rate=.0001):
theta=np.zeros((2,))
itr=0
max_itr=100
error_list=[]
while(itr<=max_itr):
grad=gradient(X,Y,theta)
e=error(X,Y,theta)
error_list.append(e)
theta[0]=theta[0]-learning_rategrad[0]
theta[1]=theta[1]-learning_rate
grad[1]
itr+=1
return theta,error_list
final_theta,error_list=gradientDescent(X,Y)
plt.plot(error_list)
plt.show()
print(final_theta)

What are you uploading as the solution in the challenge?

no, i am uploading the csv file in the challenge.

Make sure that the output format is correct. Negative accuracies occur in such cases only.

if it is in correct format then??
because i am uploading the csv file in correct format.And when i am using sklearn library linear regression function and after all of the stuff i am uploading the csv file it provide me 97% accuracy.

Your output form:
chrome_Nf6bGmG5Sa
Correct output form:
chrome_ZfuIt5NK0j

Use the following code to save your poutput as csv file:

with open('results.csv','w',newline='') as f:
    fwriter = csv.writer(f)
    fwriter.writerow(['y'])
    for i in range(y_test.shape[0]):
        fwriter.writerow(y_test[i])

so, there is an error in code or while saving the output in csv file??

Both. Firstly correct the output format.
Also, which x_test file are you using? Because the code which you’ve uploaded here shows that you are creating your own x_test using the linspace function even when you’ve imported the actual x_test file. Please correct these two things and you will obtain the correct output.

I hope it has been resolved @Aman_Rai?

Yes,Thank You For the help.

how can input value(time ) be nagative? do we have to make it positive using data preprocessing??

Actually its a dummy dataset that has been created by coding blocks so it may contain some values that may not fit the description.

I am facing issues while creating a csv file and writing my output data in it . Please Help