variance, standard deviation, correlation coefficient

Asked 2 years ago, Updated 2 years ago, 283 views

Which part of this should I change to produce variance, standard deviation, and correlation coefficient?

import matplotlib.pyplot as plt
import statistics
import numpy
x = [ ]
y = [ ]
for i in range (1901, 2021):
    x.append(i)
    y.append(numpy.sin(i))
a=statistics.variance(y)
b=print("...".format(...), numpy.corrcoef
print("Distributed={}.format(a))
print("Standard deviation={}.format(b))
cor=numpy.correcoef(x,y)
print("correlation coefficient={}".format(cor[1][0]))

python python3 matplotlib

2022-09-30 21:57

2 Answers

ModuleNotFoundError is probably because there is no library.
pip install matplotlib
pip install numpy
Please go to the .The library may be missing.


2022-09-30 21:57

Modify , to . (dot) as indicated in the comment.

import matplotlib.pyplot as plt 
import statistics
import numpy

x = [ ]
y = [ ]
for i in range (1901, 2021):
    x.append(i)
    y.append(numpy.sin(i))

a=statistics.variance(y)
b=statistics.stdev(y)
print("Distributed={}.format(a))
print("Standard deviation={}.format(b))
cor=numpy.corrcoef(x,y)
print("correlation coefficient={}".format(cor[1][0]))


2022-09-30 21:57

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.