一般来说,SciKit和线性代数/机器学习相当新,所以我似乎无法解决以下问题:
我有一套训练集和一组测试数据,包含连续和离散/分类值.CSV文件加载到Pandas DataFrames中并匹配形状,即(1460,81)和(1459,81).但是,在使用Pandas的get_dummies后,DataFrame的形状变为(1460,306)和(1459,294).因此,当我使用SciKit线性回归模块进行线性回归时,它会为306个变量构建一个模型,并尝试使用它来预测一个只有294个变量的模型.这自然会导致以下错误:
ValueError: shapes (1459,294) and (306,1) not aligned: 294 (dim 1) != 306 (dim 0)
Run Code Online (Sandbox Code Playgroud)
我怎么能解决这个问题?我可以以某种方式重塑(1459年,294年)以匹配另一个吗?
谢谢,我希望我已经明确了:)
python machine-learning linear-regression pandas scikit-learn
我正在尝试对我在 UCI 机器学习数据库中找到的一些文本识别数据进行 ak 最近邻预测。( https://archive.ics.uci.edu/ml/datasets/Letter+Recognition )
我交叉验证了数据并测试了准确性,没有问题,但我无法运行classifier.predict()。任何人都可以阐明为什么我会收到此错误?我在 sklearn 网站上阅读了维度诅咒,但实际上我在修复代码时遇到了麻烦。
到目前为止,我的代码如下:
import pandas as pd
import numpy as np
from sklearn import preprocessing, cross_validation, neighbors
df = pd.read_csv('KMeans_letter_recog.csv')
X = np.array(df.drop(['Letter'], 1))
y = np.array(df['Letter'])
X_train, X_test, y_train, y_test = cross_validation.train_test_split(X, y, test_size = 0.2) #20% data used
clf = neighbors.KNeighborsClassifier()
clf.fit(X_train, y_train)
accuracy = clf.score(X_test, y_test) #test
print(accuracy) #this works fine
example = np.array([7,4,3,2,4,5,3,6,7,4,2,3,5,6,8,4])
example = X.reshape(len(example), -1)
prediction = clf.predict(example)
print(prediction) #error
Run Code Online (Sandbox Code Playgroud)
df.head() 产生:
Letter x-box y-box box_width …Run Code Online (Sandbox Code Playgroud) numpy machine-learning nearest-neighbor python-3.x scikit-learn
我最近正在学习 PyCuda,并计划替换相机系统的一些代码以加快图像处理速度。该部分最初使用cv2.filter2D。我的目的是用GPU加速处理。
Time for signal.convolve2d: 1.6639747619628906
Time for cusignal.convolve2d: 0.6955723762512207
Time for cv2.filter2D: 0.18787837028503418
Run Code Online (Sandbox Code Playgroud)
然而,cv2.filter2D 似乎仍然是三者中最快的。如果输入是一长串图像,自定义 PyCuda 内核是否会超过 cv2.filter2D?
import time
import cv2
from cusignal.test.utils import array_equal
import cusignal
import cupy as cp
import numpy as np
from scipy import signal
from scipy import misc
ascent = misc.ascent()
ascent = np.array(ascent, dtype='int16')
ascentList = [ascent]*100
filterSize = 3
scharr = np.ones((filterSize, filterSize), dtype="float") * (1.0 / (filterSize*filterSize))
startTime = time.time()
for asc in ascentList:
grad = signal.convolve2d(asc, scharr, …Run Code Online (Sandbox Code Playgroud) python ×2
scikit-learn ×2
cupy ×1
cusignal ×1
numpy ×1
opencv ×1
pandas ×1
python-3.x ×1
scipy ×1