ScikitLearn,如何在外部数据集上使用局部线性嵌入

问题描述

使用以下网站: https://scikit-learn.org/stable/auto_examples/manifold/plot_lle_digits.html#sphx-glr-auto-examples-manifold-plot-lle-digits-py https://scikit-learn.org/stable/auto_examples/manifold/plot_swissroll.html#sphx-glr-auto-examples-manifold-plot-swissroll-py

我设法在 MNIST 数据集和 swissroll 数据集上获得了 LLE,但不知何故我不知道该怎么做才能让它在 https://www.kaggle.com/manufacturingai/predicting-fraud-w-fast-ai 等外部数据集上运行。

我的尝试如下:

import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
%matplotlib inline
from matplotlib import offsetbox
from sklearn import (manifold,datasets)

n_neighbors = 30
f_fontsize = 8
data = np.genfromtxt('../content/creditcard.csv',skip_header=True)
features = data[:,:3]
targets = data[:,3]   # The last column is identified as the target

def plotcreditfraudfig(X,color,X_sr,err):

  fig = plt.figure()

  ax = fig.add_subplot(211,projection='3d')
  ax.scatter(X[:,0],X[:,1],2],cmap=plt.cm.Spectral)

  ax.set_title("Original data")
  ax = fig.add_subplot(212)
  ax.scatter(X_sr[:,X_sr[:,cmap=plt.cm.Spectral)
  plt.axis('tight')
  plt.xticks([]),plt.yticks([])
  plt.title('Projected data')
  plt.show()

clf = manifold.LocallyLinearEmbedding(n_neighbors=n_neighbors,n_components=2,method='standard')
clf.fit(X=features,y=targets)

print("Done. Reconstruction error: %g" %clf.reconstruction_error_)

X_llecf=clf.transform(X)
plot_embedding(X_llecf,"Locally Linear Embedding")
---------------------------------------------------------------------------

IndexError                                Traceback (most recent call last)

<ipython-input-106-91224a1ba194> in <module>()
      1 data = np.genfromtxt('../content/creditcard.csv',skip_header=True)
----> 2 features = data[:,:3]
      3 targets = data[:,3]   # The last column is identified as the target
      4 
      5 clf = manifold.LocallyLinearEmbedding(n_neighbors=n_neighbors,method='standard')

IndexError: too many indices for array: array is 1-dimensional,but 2 were indexed

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)