[Solved] TypeError: 'module' object is not callable

I am trying to create a regression line to a scatterplot but when I try to append the trace with:

        n=np.size(x_reg)
        mean_x, mean_y=np.mean(x_reg), np.mean(y_reg)
        
        SS_xy= np.sum(y_reg*x_reg - n*mean_y*mean_x)
        SS_xx=np.sum(x_reg*x_reg - n*mean_x*mean_x)
        
        b_1=SS_xy/SS_xx
        b_0=mean_y-b_1*mean_x
        y_pred=b_0+b_1*x_reg
        fig.append_trace(trace=go.scatter(
                x=x_reg,
                y=y_pred,
                ), row=int(rowlist[math.floor(r_i)]) , col=1)

I get the error

, line 282, in corel_plot
    y=y_pred,
TypeError: 'module' object is not callable

The type of both x_reg and y_pred is pandas.core.series.Series of equal length, with values of type numpy.float64.
I tried to make a list of them but that did still give the same error.
Also, since x and y are of same type, and same length it is pretty strange that the error is only thrown for y, and x apparently is executed without an issue.

Best for #api:python

I found the error actually:
Simple typo due to case sensitivity.
Needs to be

trace=go.Scatter(

and not:

trace=go.scatter(
4 Likes

This error statement TypeError: โ€˜moduleโ€™ object is not callable is raised as you are being confused about the Class name and Module name. The problem is in the import line . You are importing a module, not a class. This happend because the module name and class name have the same name .
If you have a class MyClass in a file called MyClass.py , then you should write:

from MyClass import MyClass

I new to Plotly. your answer is absolutely correct. But while pressing โ€˜shiftโ€™+โ€˜tabโ€™, suggestion contains the lower case scatter. then why itโ€™s throwing module error?