0

My program throws an error:

TypeError: 'DataFrame' object is not callable

I am using numpy and pandas with python 3.6. The error is encountered at line 15 identified with "**" below.

import pandas as pd
import numpy as np
import sklearn
from sklearn import linear_model
from sklearn.utils import shuffle

data = pd.read_csv("student-mat.csv", sep=";")

print("Starting data manipulation...")
data = data[["G1", "G2", "G3", "studytime", "failures", "absences"]]

predict = "G3"

x = np.array(data.drop([predict], 1))
y = np.array(data([predict]))


x_train, x_test, y_train, y_test = sklearn.model_selection.train_test_split(x, y, test_size=0.1)

linear = linear_model.LinearRegression()
linear.fit(x_train, y_train)
acc = linear.score(x_test, y_test)

print("Accuracy: " + str(acc))

print("Coefficient: " + str(linear.coef_))
print("Intercept: " + str(linear.intercept_))
0

1 Answer 1

1

Change your line

y = np.array(data([predict]))

to

y = np.array(data[predict])

When you use () after any variable, python expects it to be a function and that's what error message is about

Use only [] to access column from any dataframe i.e. data["predict"]

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.