Python Forum
AttributeError: 'DataFrame' object has no attribute 'Articles'
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
AttributeError: 'DataFrame' object has no attribute 'Articles'
#1
Purposes I want to plot feathers importance for data prediction and training and testing

Running Time Error: AttributeError: 'DataFrame' object has no attribute 'Articles'

Error:
Traceback (most recent call last): File "D:/Clustering/text-cluster-master/similarity.py", line 68, in <module> y = X.Articles.copy() File "D:\Python3.8.0\Python\lib\site-packages\pandas\core\generic.py", line 5460, in __getattr__ return object.__getattribute__(self, name) AttributeError: 'DataFrame' object has no attribute 'Articles'
Codes lines:

y = X.Articles.copy()
X.drop(['Articles'], axis=1, inplace=True)
Reply
#2
you are not showing enough code.
Show where X is defined.
Reply
#3
X is defined as
X = pd.read_csv(r"D:\\Clustering\\text-cluster-master\\Articles.csv", error_bad_lines=False)
X.head()
Reply
#4
The error is
Error:
AttributeError: 'DataFrame' object has no attribute 'Articles'
I don't see how X could have any attribute named Articles.
It has never been defined.
Reply
#5
@Larz60+ have a look at the overall codes
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import matplotlib

from sklearn.model_selection import train_test_split
from sklearn import preprocessing
from sklearn.decomposition import PCA
from sklearn.neighbors import KNeighborsClassifier


matplotlib.style.use('ggplot') # Look Pretty


def plotDecisionBoundary(model, X, y):
  fig = plt.figure()
  ax = fig.add_subplot(111)

  padding = 0.6
  resolution = 0.0025
  colors = ['royalblue','forestgreen','ghostwhite']

  # Calculate the boundaris
  x_min, x_max = X[:, 0].min(), X[:, 0].max()
  y_min, y_max = X[:, 1].min(), X[:, 1].max()
  x_range = x_max - x_min
  y_range = y_max - y_min
  x_min -= x_range * padding
  y_min -= y_range * padding
  x_max += x_range * padding
  y_max += y_range * padding


  xx, yy = np.meshgrid(np.arange(x_min, x_max, resolution),
                       np.arange(y_min, y_max, resolution))


  Z = model.predict(np.c_[xx.ravel(), yy.ravel()])
  Z = Z.reshape(xx.shape)

  # Plot the contour map
  cs = plt.contourf(xx, yy, Z, cmap=plt.cm.terrain)

  # Plot the test original points as well...
  for label in range(len(np.unique(y))):
    indices = np.where(y == label)
    plt.scatter(X[indices, 0], X[indices, 1], c=colors[label], label=str(label), alpha=0.8)

  p = model.get_params()
  plt.axis('tight')
  plt.title('K = ' + str(p['n_neighbors']))



X = pd.read_csv(r"D:\\Clustering\\text-cluster-master\\Articles.csv", error_bad_lines=False)
X.head()

y = X.Articles.copy()
X.drop(['Articles'], axis=1, inplace=True)



y = y.astype("category").cat.codes


X.fillna(X.mean(), inplace=True)


X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.33,
                                                    random_state=1)


normaliser = preprocessing.Normalizer().fit(X_train)


X_train_normalised = normaliser.transform(X_train)
X_train = pd.DataFrame(X_train_normalised)

X_test_normalised = normaliser.transform(X_test)
X_test = pd.DataFrame(X_test_normalised)


pca_reducer = PCA(n_components=2).fit(X_train_normalised)

X_train = pca_reducer.transform(X_train_normalised)
X_test = pca_reducer.transform(X_test_normalised)


knn = KNeighborsClassifier(n_neighbors=9)
knn.fit(X_train, y_train)

plotDecisionBoundary(knn, X_train, y_train)


print(knn.score(X_test, y_test))

plt.show()
Reply
#6
Anldra12 Wrote:@Larz60+ have a look at the overall codes

FYI: Because of the volume of posts, it's important to provide enough code on your first post.

Error message shows error to be on line 68, which is now line 58, so doesn't match.
code should match error message.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  FileNotFoundError: [Errno 2] No such file or directory: 'model/doc2vec.model/Articles Anldra12 10 860 Jun-11-2021, 04:48 PM
Last Post: snippsat
  AttributeError: 'Node' object has no attribute 'insert' Anldra12 4 700 May-11-2021, 10:12 AM
Last Post: Anldra12
  AttributeError: module 'string' has no attribute 'uppercase' Anldra12 10 1,400 Apr-23-2021, 05:30 PM
Last Post: ibreeden
  AttributeError: 'tuple' object has no attribute 'format' Anldra12 7 3,206 Apr-13-2021, 07:45 AM
Last Post: Anldra12
Lightbulb 'str' object has no attribute 'to_csv' brunolelli 3 2,097 Mar-25-2021, 06:40 AM
Last Post: ndc85430
  AttributeError: 'Message' object has no attribute 'split' helpme1 2 938 Mar-14-2021, 11:25 AM
Last Post: helpme1
  AttributeError class object has no attribute list object scttfnch 5 673 Feb-24-2021, 10:03 PM
Last Post: scttfnch
  AttributeError: 'NoneType' object has no attribute 'next' loves 2 1,889 Dec-15-2020, 11:30 PM
Last Post: bowlofred
  How to Locate an Attribute's Parent Object? calvinsomething 5 724 Nov-13-2020, 01:52 AM
Last Post: calvinsomething
  How to split dataframe object rows to columns Mekala 1 486 Nov-12-2020, 04:18 PM
Last Post: michael1789

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020