是否有任何python包允许有效计算多变量正常pdf?
它似乎没有被包含在Numpy/Scipy中,并且令人惊讶的是谷歌搜索没有发现任何有用的东西.
我正在尝试使用python进行分类.我正在使用Naive Bayes MultinomialNB分类器用于网页(从网络检索数据到文本,稍后我将此文本分类为:web分类).
现在,我正在尝试对这些数据应用PCA,但是python会给出一些错误.
我的朴素贝叶斯分类代码:
from sklearn import PCA
from sklearn import RandomizedPCA
from sklearn.feature_extraction.text import CountVectorizer
from sklearn.naive_bayes import MultinomialNB
vectorizer = CountVectorizer()
classifer = MultinomialNB(alpha=.01)
x_train = vectorizer.fit_transform(temizdata)
classifer.fit(x_train, y_train)
Run Code Online (Sandbox Code Playgroud)
这种天真的贝叶斯分类给出了输出:
>>> x_train
<43x4429 sparse matrix of type '<class 'numpy.int64'>'
with 6302 stored elements in Compressed Sparse Row format>
>>> print(x_train)
(0, 2966) 1
(0, 1974) 1
(0, 3296) 1
..
..
(42, 1629) 1
(42, 2833) 1
(42, 876) 1
Run Code Online (Sandbox Code Playgroud)
比我尝试在我的数据上应用PCA(temizdata):
>>> v_temizdata = vectorizer.fit_transform(temizdata) …Run Code Online (Sandbox Code Playgroud) 我在Python中使用FFT实现了一个问题.我有完全奇怪的结果.好吧,我想打开图像,获取RGB中每个像素的值,然后我需要在它上面使用fft,然后再次转换为图像.
我的步骤:
1)我正在使用Python中的PIL库打开图像
from PIL import Image
im = Image.open("test.png")
Run Code Online (Sandbox Code Playgroud)
2)我得到了像素
pixels = list(im.getdata())
Run Code Online (Sandbox Code Playgroud)
3)我将每个像素分成r,g,b值
for x in range(width):
for y in range(height):
r,g,b = pixels[x*width+y]
red[x][y] = r
green[x][y] = g
blue[x][y] = b
Run Code Online (Sandbox Code Playgroud)
4).我们假设我有一个像素(111,111,111).并在所有红色值上使用fft
red = np.fft.fft(red)
Run Code Online (Sandbox Code Playgroud)
然后:
print (red[0][0], green[0][0], blue[0][0])
Run Code Online (Sandbox Code Playgroud)
我的输出是:
(53866+0j) 111 111
Run Code Online (Sandbox Code Playgroud)
我认为这是完全错误的.我的图像是64x64,而来自gimp的FFT完全不同.实际上,我的FFT只给出了具有巨大值的数组,这就是为什么我的输出图像是黑色的.
你知道问题出在哪里吗?
[编辑]
我按照建议改变了
red= np.fft.fft2(red)
Run Code Online (Sandbox Code Playgroud)
然后我扩展它
scale = 1/(width*height)
red= abs(red* scale)
Run Code Online (Sandbox Code Playgroud)
而且,我只得到黑色图像.
[EDIT2]
假设我不想打开它并保存为灰度图像.所以我这样做.
def getGray(pixel):
r,g,b = pixel
return (r+g+b)/3
im = Image.open("test.png")
im.load()
pixels = list(im.getdata())
width, …Run Code Online (Sandbox Code Playgroud) 我已经使用 pyenv 很长时间了,没有任何问题。我正确设置了它并且一切正常。
然而,当我试图解决另一个问题时,我运行了一些行,这破坏了我的 pyenv 安装。
现在,当我激活任何 virtualenv 时,它会尝试使用系统的 python 而不是 pyenv 的:
$ pyenv activate foo
(foo) $ which python
/usr/bin/python
(foo) $ pip --version
pip 20.3.4 from /home/rodrigo/.local/lib/python2.7/site-packages/pip (python 2.7)
Run Code Online (Sandbox Code Playgroud)
我不确定到底是哪一行破坏了它,可能是以下一行:(foo) $ pip install --upgrade pip setuptools wheel 来自环境foo(我在它仍然有效时运行它),但可能是另一行。
我已经检查过~/.bashrc文件,没问题;重新启动控制台,甚至换了不同的环境foo2,问题仍然存在......
我已经检查了类似的问题,例如this或this,但这些与我已经测试过并且没问题的配置错误有关。
我正在使用 Ubuntu 18.04 LTS 和 pyenv 2.0.3-8-gad880754
更新我重新安装了 pyenv 但它仍然不起作用
当我尝试通过ajax调用渲染panelGroup时,它会给出未知的id.
<h:form id="form1" prependId=false>
<h:panelGroup id="panel1">
<h:dataTable/>
<ui:repeat value="#{bean.page}" var="page">
<h:commandLink value="#{page}">
<f:ajax execute="@form" render="panel1" listener="#{bean.page}" />
</h:commandLink>
</ui:repeat>
</h:panelGroup>
</h:form>
Run Code Online (Sandbox Code Playgroud)
当我尝试这段代码时,它会给出未知的id panel1.我尝试了id":panel1".我犯了同样的错误.
我已经实现了自己的分类器,现在我想对其进行网格搜索,但出现以下错误: estimator.fit(X_train, y_train, **fit_params)
TypeError: fit() takes 2 positional arguments but 3 were given
我跟着这个教程,使用了scikit 官方文档提供的这个模板。我的班级定义如下:
class MyClassifier(BaseEstimator, ClassifierMixin):
def __init__(self, lr=0.1):
self.lr=lr
def fit(self, X, y):
# Some code
return self
def predict(self, X):
# Some code
return y_pred
def get_params(self, deep=True)
return {'lr'=self.lr}
def set_params(self, **parameters):
for parameter, value in parameters.items():
setattr(self, parameter, value)
return self
Run Code Online (Sandbox Code Playgroud)
我正在尝试网格搜索将其抛出如下:
params = {
'lr': [0.1, 0.5, 0.7]
}
gs = GridSearchCV(MyClassifier(), param_grid=params, cv=4)
Run Code Online (Sandbox Code Playgroud)
编辑我
我是这样称呼它的:gs.fit(['hello …
我正在尝试运行这个卷积自动编码器示例,但使用我自己的数据,因此我根据我的图像修改了它的InputLayer。然而,在输出层上存在尺寸问题。我确信问题出在 UpSampling 上,但我不确定为什么会发生这种情况:代码如下。
N, H, W = X_train.shape
input_img = Input(shape=(H,W,1)) # adapt this if using `channels_first` image data format
x = Conv2D(16, (3, 3), activation='relu', padding='same')(input_img)
x = MaxPooling2D((2, 2), padding='same')(x)
x = Conv2D(8, (3, 3), activation='relu', padding='same')(x)
x = MaxPooling2D((2, 2), padding='same')(x)
x = Conv2D(8, (3, 3), activation='relu', padding='same')(x)
encoded = MaxPooling2D((2, 2), padding='same')(x)
# at this point the representation is (4, 4, 8) i.e. 128-dimensional
x = Conv2D(8, (3, 3), activation='relu', padding='same')(encoded)
x = UpSampling2D((2, …Run Code Online (Sandbox Code Playgroud) 我正好有这个问题:
在张量流服务模型上运行预测后,我得到了这个PredictResponse对象作为输出:
outputs {
key: "scores"
value {
dtype: DT_FLOAT
tensor_shape {
dim {
size: 1
}
dim {
size: 2
}
}
float_val: 0.407728463411
float_val: 0.592271506786
}
}
Run Code Online (Sandbox Code Playgroud)
如该问题的建议,我尝试使用:result.outputs ['outputs']。float_val
但是它返回类型 <type google.protobuf.pyext._message.RepeatedScalarContainer>
它是由这段代码产生的,灵感来自inception_client.py示例:
channel = implementations.insecure_channel(host, int(port))
stub = prediction_service_pb2.beta_create_PredictionService_stub(channel)
result = stub.Predict(request, 10.0) # 10 secs timeout
Run Code Online (Sandbox Code Playgroud)
提前致谢!
python ×7
scikit-learn ×2
autoencoder ×1
dft ×1
fft ×1
image ×1
jsf-2 ×1
keras ×1
naivebayes ×1
numpy ×1
pca ×1
pip ×1
pyenv ×1
scipy ×1
tensorflow ×1