It would be nice to see your train_generator code for clarity, but it does not seem to be a torch DataLoader. In this case, you should probably convert your arrays to tensors manually. There are several ways to do so:
torch.from_numpy(numpy_array)- for numpy arrays;torch.as_tensor(list)- for common lists and tuples;torch.tensor(array)should also work but the above ways will avoid copying the data when possible.
Hi,
I'm trying to create a numpy v-stack and creating 3 np.array's for it, by filling them with a loop:
I get the error: 'AttributeError: 'numpy.ndarray' object has no attribute 'np' . I think I'm using the wrong notation to append to the empty arrays:
neighbor_id = [id_ for id_ in range(1, n_obs) if id_ != user_id]
neighbor_id_arr = np.array(neighbor_id)
similarity = np.array([])
num_interactions = np.array([])
# get similarity and num_interactions
for id_ in neighbor_id:
similarity.np.append(np.dot(user_item.loc[user_id],user_item.loc[id_])) #The issue is here, I think
num_interactions.np.append(user_interactions.loc[id_])
c = numpy.vstack((neighbor_id_arr, similarity,num_interactions))
Thanks!
James
scikit learn - AttributeError: 'numpy.ndarray' object has no attribute 'fit' - Data Science Stack Exchange
Medical Data Visualizer AttributeError: 'numpy.ndarray' object has no attribute
pandas - 'numpy.ndarray' object has no attribute 'plot' - Data Science Stack Exchange
'numpy.ndarray' object has no attribute 'numpy'.
Videos
It would be helpful if you could post the full stack trace, so that we can see which line your error occurs at. In general, the more information you can provide in a question, the better.
In this case, it looks like your full_model_pipeline may somehow become a numpy array. Since you have a one-element pipeline, you could try changing
full_model_pipeline = Pipeline(steps =[
('full_pipeline',full_pipeline),
('model',LinearRegression())
])
full_model_pipeline.fit(X_train,y_train)
to
model = LinearRegression()
model.fit(X_train, y_train)
I believe you need to add () where you add scaler to the pipeline: ('std_scaler',StandardScaler) --> ('std_scaler',StandardScaler())
The solution:
The given dataset was already an array, so I didn’t need to call .values.
The problem lies in the following line:
df = StandardScaler().fit_transform(df)
It returns a NumPy array (see the documentation), which does not have a drop function. You would have to convert it into a pd.DataFrame first!
new_df = pd.DataFrame(StandardScaler().fit_transform(df), columns=df.columns, index=df.index)