我有一个2D numpy数组.有没有办法在其上创建包含第一k行和所有列的视图?
关键是要避免复制基础数据(数组太大,以至于无法制作部分副本.)
我想将scikits.learn.hmm.GaussianHMM与不同长度的训练序列相匹配.然而,拟合方法通过这样做来防止使用不同长度的序列
obs = np.asanyarray(obs)
Run Code Online (Sandbox Code Playgroud)
它只适用于同样形状的数组列表.有人提示如何继续吗?
是否有可能在scikit-learn中缺少值?他们应该如何代表?我找不到任何关于这方面的文件.
根据scikit-learn用户指南,我安装了scikit-learn使用pip install -U scikit-learn.
所以使用pip search scikit-learn,我得到这个搜索结果:
scikit-learn - A set of python modules for machine learning and data mining
INSTALLED: 0.12.1 (latest)
Run Code Online (Sandbox Code Playgroud)
但是当我进入Python尝试时import sklearn,我得到了一个ImportError: No module named sklearn.这真的应该有效.
我在Mac OS 10.6.8上使用Enthought免费发布Python(2.7.3),使用NumPy 1.6.1和SciPy 0.10.1.是的,我知道EPD Free带有scikit-learn但是pip应该升级我的版本,以便我可以实际使用scikit-learn.
我需要一些关于为Python选择统计软件包的建议,我做了很多搜索,但不确定我是否做得对,特别是statsmodels和scipy.stats之间的区别.
我知道的一件事是scikits命名空间是scipy的特定"分支",而以前的scikits.statsmodels现在称为statsmodels.另一方面,还有scipy.stats.两者之间有什么区别,哪一个是Python 的统计软件包?
谢谢.
- 编辑 -
我更改了标题,因为有些答案与问题没有关系,我认为这是因为标题不够明确.
在大多数Scikit-learn算法中,数据必须作为Bunch对象加载.对于教程中的许多示例,load_files()或其他函数用于填充Bunch对象.像load_files()这样的函数希望数据以某种格式存在,但我有以不同格式存储的数据,即每个字段都包含字符串的CSV文件.
如何解析此并以Bunch对象格式加载数据?
我正在比较两个Naive Bayes分类器:一个来自NLTK,另一个来自scikit-learn.我正在处理一个多类分类问题(3个类:正(1),负(-1)和中性(0)).
在不执行任何特征选择的情况下(即,使用所有可用功能),并使用70,000个实例的训练数据集(噪声标记,实例分布为17%为正,4%为负,78%为中性),我训练了两个分类器,第一个是nltk.NaiveBayesClassifier,第二个是sklearn.naive_bayes.MultinomialNB(带fit_prior=True).
训练结束后,我在30,000个实例的测试集上评估了分类器,得到了以下结果:
**NLTK's NaiveBayes**
accuracy: 0.568740
class: 1
precision: 0.331229
recall: 0.331565
F-Measure: 0.331355
class: -1
precision: 0.079253
recall: 0.446331
F-Measure: 0.134596
class: 0
precision: 0.849842
recall: 0.628126
F-Measure: 0.722347
**Scikit's MultinomialNB (with fit_prior=True)**
accuracy: 0.834670
class: 1
precision: 0.400247
recall: 0.125359
F-Measure: 0.190917
class: -1
precision: 0.330836
recall: 0.012441
F-Measure: 0.023939
class: 0
precision: 0.852997
recall: 0.973406
F-Measure: 0.909191
**Scikit's MultinomialNB (with fit_prior=False)**
accuracy: 0.834680
class: 1
precision: 0.400380
recall: 0.125361 …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用python库scikit-tensor分解3D矩阵.我设法将我的Tensor(尺寸为100x50x5)分解为三个矩阵.我的问题是如何使用Tensor分解产生的分解矩阵再次组合初始矩阵?我想检查分解是否有任何意义.我的代码如下:
import logging
from scipy.io.matlab import loadmat
from sktensor import dtensor, cp_als
import numpy as np
//Set logging to DEBUG to see CP-ALS information
logging.basicConfig(level=logging.DEBUG)
T = np.ones((400, 50))
T = dtensor(T)
P, fit, itr, exectimes = cp_als(T, 10, init='random')
// how can I re-compose the Matrix T? TA = np.dot(P.U[0], P.U[1].T)
Run Code Online (Sandbox Code Playgroud)
我正在使用scikit-tensor库函数cp_als提供的规范分解.此外,分解矩阵的预期维数是多少?
我正在尝试使用pip工具安装scikits.audiolab.Pip似乎python setup.py egg_info从scikits.audiolab源目录中运行命令.当它这样做时,我收到此错误:
Andrews-MacBook-Pro-2:scikits.audiolab-0.11.0 andrewhannigan$ pip install scikits.audiolab
Collecting scikits.audiolab
Using cached scikits.audiolab-0.11.0.tar.gz
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 20, in <module>
File "/private/var/folders/xb/qwlsm44s1wxfr82kytrgjtl80000gn/T/pip-build-vSZaU8/scikits.audiolab/setup.py", line 32, in <module>
from numpy.distutils.core import setup
ImportError: No module named numpy.distutils.core
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /private/var/folders/xb/qwlsm44s1wxfr82kytrgjtl80000gn/T/pip-build-vSZaU8/scikits.audiolab
Run Code Online (Sandbox Code Playgroud)
问题显然是无法导入numpy.distutils.core.查看setup.py脚本,这个导入很早就发生了(在下面的代码片段的底部):
#! /usr/bin/env python
# Last Change: Fri Mar 27 05:00 PM 2009 J
# Copyright (C) 2006-2007 …Run Code Online (Sandbox Code Playgroud) scikits ×10
python ×9
scikit-learn ×5
numpy ×2
scipy ×2
data-science ×1
math ×1
missing-data ×1
nltk ×1
pip ×1
random ×1
statsmodels ×1