glm-tools / pyglmnet

Python implementation of elastic-net regularized generalized linear models
http://glm-tools.github.io/pyglmnet/
MIT License
279 stars 83 forks source link

TypeError: ufunc 'add' output (typecode 'O') could not be coerced to provided outp ut parameter (typecode 'd') according to the casting rule ''same_kind'' #305

Closed jpainam closed 3 years ago

jpainam commented 5 years ago

Hi, I'm runing a code and got this error. Any help will be appreciated. Here is my code

import numpy as np
import scipy.sparse as sps
from sklearn.preprocessing import StandardScaler
from pyglmnet import GLM
import pandas as pd
glm = GLM(distr='poisson', score_metric='pseudo_R2')
df = pd.read_excel("../pseudo.xlsx")
df = df.fillna(value=0)
dataset = df.values
Xtrain = dataset[:, 3:]
ytrain = dataset[:, 2]
scaler = StandardScaler().fit(Xtrain)
glm.fit(scaler.transform(Xtrain), ytrain)

pseudor = glm[0].score(scaler.transform(Xtrain), ytrain)
print(pseudor)

and the error

\lib\site-
packages\pyglmnet\pyglmnet.py", line 389, in _grad_L2loss
    X[selector, :]))
TypeError: ufunc 'add' output (typecode 'O') could not be coerced to p
rovided output parameter (typecode 'd') according to the casting rule
''same_kind''
jasmainak commented 5 years ago

unfortunately I cannot help unless you share the data somehow.

alternatively try to reproduce the behavior with random or simulated data so you mimic the issue that your dataset has