我试图在python中导入统计模块。它在我执行程序时给出了一条错误消息。
这是我的代码:
from statistics import mean
import numpy as np
import matplotlib.pyplot as plt
xs = np.array([1,2,3,4,5,6,7,8])
ys = np.array([2,8,5,0,5,7,3,6])
def best_fit_line(xs ,ys):
m = ( ((mean(xs)* mean(ys))- mean(xs*ys)) /
(mean(xs)*mean(xs))-(mean(xs*xs)))
return m
m = best_fit_line(xs,ys)
错误消息:
Traceback (most recent call last):
File "/home/kudzai/Documents/Machine Learning/LinearRegAlg.py", line 1, in <module>
from statistics import mean
ImportError: No module named statistics
答案 0 :(得分:3)
在Python 3.4中添加了statistics
module。也许您正在使用较旧的Python版本。
如果由于某种原因无法升级,您也可以使用.config
的{{1}}函数:EBS
等。对于numpy
数组,它可能更快太