I need to find the pvalue. for a multiLinearRegression. However, I can not use import statsmodels.formula.api as sm. It throws a error for me :( is there a way to find the pvalue without using statsmodels? this is what I have so far.
import numpy
from scipy.stats import pearsonr
data = numpy.genfromtxt("2-2.4.txt",delimiter=",")
x = data[:,6]
x2 = data[:,7]
x3 = data[:,8]
x4 = data[:,9]
y = data[:,-1]
r, p = pearsonr(x,x2,x3,x4, y) # how do I find the pvalue when working with multiple variables
error I get with statsmodel when importing
File "C:\Python27\lib\site-packages\statsmodels\formula\__init__.py", line 4, in <module>
from formulatools import handle_formula_data
File "C:\Python27\lib\site-packages\statsmodels\formula\formulatools.py", line 1, in <module>
import statsmodels.tools.data as data_util
File "C:\Python27\lib\site-packages\statsmodels\tools\__init__.py", line 1, in <module>
from tools import add_constant, categorical
File "C:\Python27\lib\site-packages\statsmodels\tools\tools.py", line 14, in <module>
from pandas import DataFrame
File "C:\Python27\lib\site-packages\pandas\__init__.py", line 39, in <module>
from pandas.core.api import *
File "C:\Python27\lib\site-packages\pandas\core\api.py", line 10, in <module>
from pandas.core.groupby import Grouper
File "C:\Python27\lib\site-packages\pandas\core\groupby.py", line 18, in <module>
from pandas.core.frame import DataFrame
File "C:\Python27\lib\site-packages\pandas\core\frame.py", line 39, in <module>
from pandas.core.series import Series
File "C:\Python27\lib\site-packages\pandas\core\series.py", line 2995, in <module>
import pandas.tools.plotting as _gfx # noqa
File "C:\Python27\lib\site-packages\pandas\tools\plotting.py", line 134, in <module>
if _mpl_ge_1_5_0():
File "C:\Python27\lib\site-packages\pandas\tools\plotting.py", line 129, in _mpl_ge_1_5_0
return (matplotlib.__version__ >= LooseVersion('1.5') or
File "C:\Python27\lib\distutils\version.py", line 296, in __cmp__
return cmp(self.version, other.version)
AttributeError: 'unicode' object has no attribute 'version'
Related
I am having a problem with python and pyopengl
I am just importing the modules, and getting errors, I checked and pip did install opengl and everything.
Here is my code
# ulWindow
import ulMath as ulm
import OpenGL.GL as gl
import OpenGL.GlE as gle
import glfw
def init() ->int|str:
if (not glfw.init()):
return "GLFW Failed to initialize"
return 0
And the error im getting:
Traceback (most recent call last):
File "src/ulWindow.py", line 3, in <module>
import OpenGL.GL as gl
File "/home/jack3/.local/lib/python3.8/site-packages/OpenGL/GL/__init__.py", line 4, in <module>
from OpenGL.GL.VERSION.GL_1_1 import *
File "/home/jack3/.local/lib/python3.8/site-packages/OpenGL/GL/VERSION/GL_1_1.py", line 14, in <module>
from OpenGL.raw.GL.VERSION.GL_1_1 import *
File "/home/jack3/.local/lib/python3.8/site-packages/OpenGL/raw/GL/VERSION/GL_1_1.py", line 7, in <module>
from OpenGL.raw.GL import _errors
File "/home/jack3/.local/lib/python3.8/site-packages/OpenGL/raw/GL/_errors.py", line 4, in <module>
_error_checker = _ErrorChecker( _p, _p.GL.glGetError )
File "/home/jack3/.local/lib/python3.8/site-packages/OpenGL/error.py", line 183, in __init__
self._isValid = platform.CurrentContextIsValid
File "/home/jack3/.local/lib/python3.8/site-packages/OpenGL/platform/baseplatform.py", line 15, in __get__
value = self.fget( obj )
File "/home/jack3/.local/lib/python3.8/site-packages/OpenGL/platform/baseplatform.py", line 356, in CurrentContextIsValid
return self.GetCurrentContext
File "/home/jack3/.local/lib/python3.8/site-packages/OpenGL/platform/baseplatform.py", line 15, in __get__
value = self.fget( obj )
File "/home/jack3/.local/lib/python3.8/site-packages/OpenGL/platform/egl.py", line 106, in GetCurrentContext
return self.EGL.eglGetCurrentContext
AttributeError: 'NoneType' object has no attribute 'eglGetCurrentContext'
I have absolutely no clue what is going on, can someone help me out?
I am trying to us DiffusionPipeline from hugging face to generate Image from text but the following error is being generated:
TypeError: expected string or bytes-like object
The traceback:
File "c:\Users\BHAVYA SHAH\Desktop\Artificial Intelligence\app.py", line 9, in <module>
from diffusers import DiffusionPipeline
File "C:\Users\BHAVYA SHAH\anaconda3\lib\site-packages\diffusers\__init__.py", line 26, in <module>
from .pipelines import DDIMPipeline, DDPMPipeline, KarrasVePipeline, LDMPipeline, PNDMPipeline, ScoreSdeVePipeline
File "C:\Users\BHAVYA SHAH\anaconda3\lib\site-packages\diffusers\pipelines\__init__.py", line 11, in <module>
from .latent_diffusion import LDMTextToImagePipeline
File "C:\Users\BHAVYA SHAH\anaconda3\lib\site-packages\diffusers\pipelines\latent_diffusion\__init__.py", line 6, in <module>
from .pipeline_latent_diffusion import LDMBertModel, LDMTextToImagePipeline
File "C:\Users\BHAVYA SHAH\anaconda3\lib\site-packages\diffusers\pipelines\latent_diffusion\pipeline_latent_diffusion.py", line 9, in <module>
from transformers.activations import ACT2FN
File "C:\Users\BHAVYA SHAH\anaconda3\lib\site-packages\transformers\__init__.py", line 30, in <module>
from . import dependency_versions_check
File "C:\Users\BHAVYA SHAH\anaconda3\lib\site-packages\transformers\dependency_versions_check.py", line 17, in <module>
from .utils.versions import require_version, require_version_core
File "C:\Users\BHAVYA SHAH\anaconda3\lib\site-packages\transformers\utils\__init__.py", line 34, in <module>
from .generic import (
File "C:\Users\BHAVYA SHAH\anaconda3\lib\site-packages\transformers\utils\generic.py", line 29, in <module>
from .import_utils import is_flax_available, is_tf_available, is_torch_available, is_torch_fx_proxy
File "C:\Users\BHAVYA SHAH\anaconda3\lib\site-packages\transformers\utils\import_utils.py", line 376, in <module>
torch_version = version.parse(importlib_metadata.version("torch"))
File "C:\Users\BHAVYA SHAH\anaconda3\lib\site-packages\packaging\version.py", line 49, in parse
return Version(version)
File "C:\Users\BHAVYA SHAH\anaconda3\lib\site-packages\packaging\version.py", line 264, in __init__
match = self._regex.search(version)
TypeError: expected string or bytes-like object
Help to solve this error would be much appreciated.
I have a python script for generating barcodes (code128) which works fine in IDE.
But when converted into exe, it encounters below error:
Traceback (most recent call last):
File "amazonbarcode-dubai.py", line 6, in <module>
File "PyInstaller\loader\pyimod03_importers.py", line 495, in exec_module
File "reportlab\graphics\barcode\__init__.py", line 76, in <module>
File "reportlab\graphics\barcode\__init__.py", line 42, in _reset
File "PyInstaller\loader\pyimod03_importers.py", line 495, in exec_module
File "reportlab\graphics\barcode\widgets.py", line 166, in <module>
File "reportlab\graphics\barcode\widgets.py", line 95, in _BCW
File "<string>", line 1, in <module>
ModuleNotFoundError: No module named 'reportlab.graphics.barcode.code128'
I tried import code128 from reportlab.graphics.barcode that also works fine with IDE but fails in exe.
Below is my python script:
import os
import pandas as pd
from reportlab.pdfgen import canvas
from reportlab.graphics import barcode
from reportlab.lib.units import mm
cwd = os.getcwd()
df1 = pd.read_csv(cwd+'\\exportedTable.csv')
df2 = pd.read_excel(cwd+'\\AMAZON BARCODE.xlsx',dtype=str)
df3 = pd.merge(df1,df2,left_on='ASIN',right_on='amazonasin',how='left')
df_missing = df3[df3.item.isnull()]
if df_missing.size>0:
print(df_missing.to_string())
print(df_missing.columns)
df_missing = df_missing[['Model number','UPC/EAN/ISBN','ASIN']]
df_missing.to_excel(cwd+'\\amazonmissingbarcode.xlsx',index=False)
df3 = df3.sort_values('model').reset_index()
df3['ctn'] = df3.index+1
df3 = df3[['ctn','model','barcode','amazonasin','Package tracking ID','PO number']]
df3.columns = ['ctn','model','ean','asin','accn','pono']
print(df3.to_string())
f = df3.pono.unique()[0]
cb = canvas.Canvas(f+'-big.pdf')
cb.setPageSize((100*mm,75*mm))
barcode = barcode.code128.Code128
for i,row in df3.iterrows():
barcode(row['asin'],barHeight=20*mm,barWidth=0.5*mm).drawOn(cb,9*mm,53*mm)
cb.setFont("Helvetica",10)
cb.drawCentredString(54*mm,50*mm,'ASIN : ' + row['asin'])
barcode(row['pono'],barHeight=15*mm,barWidth=0.5*mm).drawOn(cb,15*mm,32*mm)
cb.setFont("Helvetica",10)
cb.drawCentredString(54*mm,29*mm,'PO NO. : '+row['pono'])
barcode(row['accn'],barHeight=15*mm,barWidth=0.4*mm).drawOn(cb,7*mm,12*mm)
cb.setFont("Helvetica",10)
cb.drawCentredString(54*mm,9*mm,row['accn'])
cb.setFont("Helvetica-Bold",12)
cb.drawString(5*mm,4*mm,'MODEL: '+row['model'])
cb.drawRightString(95*mm,4*mm,'CTN NO.: '+str(row['ctn']))
cb.showPage()
cb.save()
I'm trying to run script like below in atom (or in pycharm)
import numpy as np
def bar(num_elems):
restrained_dofs = 0
m = np.array([[2,1], [1,2]]) / (6. * num_elems)
k = np.array([[1,-1],[-1,1]]) * num_elems
M = np.zeros((num_elems+1,num_elems+1))
K = np.zeros((num_elems+1,num_elems+1))
for i in range(num_elems):
M_temp = np.zeros((num_elems+1,num_elems+1))
K_temp = np.zeros((num_elems+1,num_elems+1))
M_temp[i:i+2,i:i+2] = m
K_temp[i:i+2,i:i+2] = k
M += M_temp
K += K_temp
for dof in range(restrained_dofs):
for i in [0,1]:
M = np.delete(M, dof, axis=i)
K = np.delete(K, dof, axis=i)
bar(1)
and I recive following terminal output
Traceback (most recent call last):
File "D:/Programowanie/Python/bar_elem.py", line 1, in <module>
import numpy as np
File "C:\Users\Admin\AppData\Local\Programs\Python\Python37\lib\site-packages\numpy\__init__.py", line 142, in <module>
from . import add_newdocs
File "C:\Users\Admin\AppData\Local\Programs\Python\Python37\lib\site-packages\numpy\add_newdocs.py", line 13, in <module>
from numpy.lib import add_newdoc
File "C:\Users\Admin\AppData\Local\Programs\Python\Python37\lib\site-packages\numpy\lib\__init__.py", line 8, in <module>
from .type_check import *
File "C:\Users\Admin\AppData\Local\Programs\Python\Python37\lib\site-packages\numpy\lib\type_check.py", line 11, in <module>
import numpy.core.numeric as _nx
File "C:\Users\Admin\AppData\Local\Programs\Python\Python37\lib\site-packages\numpy\core\__init__.py", line 35, in <module>
from . import _internal # for freeze programs
File "C:\Users\Admin\AppData\Local\Programs\Python\Python37\lib\site-packages\numpy\core\_internal.py", line 12, in <module>
from numpy.compat import basestring, unicode
File "C:\Users\Admin\AppData\Local\Programs\Python\Python37\lib\site-packages\numpy\compat\__init__.py", line 14, in <module>
from . import py3k
File "C:\Users\Admin\AppData\Local\Programs\Python\Python37\lib\site-packages\numpy\compat\py3k.py", line 14, in <module>
from pathlib import Path
File "C:\Users\Admin\AppData\Local\Programs\Python\Python37\lib\pathlib.py", line 13, in <module>
from urllib.parse import quote_from_bytes as urlquote_from_bytes
File "C:\Users\Admin\AppData\Local\Programs\Python\Python37\lib\urllib\parse.py", line 597, in <module>
_asciire = re.compile('([\x00-\x7f]+)')
AttributeError: module 're' has no attribute 'compile'
But the same script is working correctly while using Spyder3 or in Terminal.
I'm running script wit Script packacge in Atom, but other packages gives the same result.
Python 3.7.1,
Numpy 1.15.4
The problem was that the script was placed in a folder named Python, after moving it to another location everything works fine
The story
pandas, numpy, seaborn, matplotlib are installed on the system without errors. I took this code example from http://seaborn.pydata.org/examples/many_pairwise_correlations.html
Snippet
from string import letters
import numpy as np
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
sns.set(style="white")
# Generate a large random dataset
rs = np.random.RandomState(33)
d = pd.DataFrame(data=rs.normal(size=(100, 26)),
columns=list(letters[:26]))
# Compute the correlation matrix
corr = d.corr()
# Generate a mask for the upper triangle
mask = np.zeros_like(corr, dtype=np.bool)
mask[np.triu_indices_from(mask)] = True
# Set up the matplotlib figure
f, ax = plt.subplots(figsize=(11, 9))
# Generate a custom diverging colormap
cmap = sns.diverging_palette(220, 10, as_cmap=True)
# Draw the heatmap with the mask and correct aspect ratio
sns.heatmap(corr, mask=mask, cmap=cmap, vmax=.3,
square=True, xticklabels=5, yticklabels=5,
linewidths=.5, cbar_kws={"shrink": .5}, ax=ax)
It results in the following error:
Traceback (most recent call last):
File "seaborn-example.py", line 4, in <module>
import seaborn as sns
File "/usr/local/lib/python2.7/site-packages/seaborn/__init__.py", line 6, in <module>
from .rcmod import *
File "/usr/local/lib/python2.7/site-packages/seaborn/rcmod.py", line 8, in <module>
from . import palettes, _orig_rc_params
File "/usr/local/lib/python2.7/site-packages/seaborn/palettes.py", line 12, in <module>
from .utils import desaturate, set_hls_values, get_color_cycle
File "/usr/local/lib/python2.7/site-packages/seaborn/utils.py", line 12, in <module>
import matplotlib.pyplot as plt
File "/usr/local/lib/python2.7/site-packages/matplotlib/pyplot.py", line 115, in <module>
_backend_mod, new_figure_manager, draw_if_interactive, _show = pylab_setup()
File "/usr/local/lib/python2.7/site-packages/matplotlib/backends/__init__.py", line 32, in pylab_setup
globals(),locals(),[backend_name],0)
File "/usr/local/lib/python2.7/site-packages/matplotlib/backends/backend_tkagg.py", line 6, in <module>
from six.moves import tkinter as Tk
File "/usr/local/lib/python2.7/site-packages/six.py", line 203, in load_module
mod = mod._resolve()
File "/usr/local/lib/python2.7/site-packages/six.py", line 115, in _resolve
return _import_module(self.mod)
File "/usr/local/lib/python2.7/site-packages/six.py", line 82, in _import_module
__import__(name)
File "/usr/local/lib/python2.7/lib-tk/Tkinter.py", line 39, in <module>
import _tkinter # If this fails your Python may not be configured for Tk
ImportError: No module named _tkinter
Referred Install tkinter for Python for installing tkinter
yum install -y tkinter tk-devel
Then I followed this for rebuilding Python
https://github.com/h2oai/h2o-2/wiki/installing-python-2.7-on-centos-6.3.-follow-this-sequence-exactly-for-centos-machine-only
And got this when I tried the rebuilding - still some issue with tkinter:
Traceback (most recent call last):
File "seaborn-example.py", line 22, in <module>
f, ax = plt.subplots(figsize=(11, 9))
File "/usr/local/lib/python2.7/site-packages/matplotlib/pyplot.py", line 1203, in subplots
fig = figure(**fig_kw)
File "/usr/local/lib/python2.7/site-packages/matplotlib/pyplot.py", line 535, in figure
**kwargs)
File "/usr/local/lib/python2.7/site-packages/matplotlib/backends/backend_tkagg.py", line 81, in new_figure_manager
return new_figure_manager_given_figure(num, figure)
File "/usr/local/lib/python2.7/site-packages/matplotlib/backends/backend_tkagg.py", line 89, in new_figure_manager_given_figure
window = Tk.Tk()
File "/usr/local/lib/python2.7/lib-tk/Tkinter.py", line 1745, in __init__
self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
_tkinter.TclError: no display name and no $DISPLAY environment variable
What is wrong here?
At the beginning of the file
import matplotlib
matplotlib.use('Agg')