When running the following code
x = data1
y = data2
X = sm.add_constant(x)
result = (sm.OLS(y, X)).fit()
print(result.summary)
Error: valueerror: the indexes for endog and exog are not aligned
Solutions:
1. Check the data type: it has nothing to do with the service or dataframe type, and it has nothing to do with whether the data types of Y and X are consistent
2. Check data length: len (y) and Len (x) have the same length
3. It is found that although the length of len is the same, the index value of data is different. That’s the problem.
Because my x data is vertically combined by two dataframe data through concat, the index values of the data are different.
As shown in the figure below:
The complete data are as follows:
date
0 20180101
1 20180102
2 20180103
3 20180104
4 20180105
5 20180106
But the consolidated data is presented in this way, but:
date
0 20180101
1 20180102
2 20180103
3 20180104
0 20180105
1 20180106
Because the index values on the left side of the two groups of service data used for calculation are different, an error is reported. Solution:
Whether the original data is of dataframe or service type, it is converted to list type first. Take dataframe data as an example
datalist = data['close'].tolist() # change dataframe to list
datalist = data + templist # list MERGER
dataf = pd.DataFrame(datalist, columns=['close']) # list TO dataframe
After a series of data processing in the early stage, the program is executed again, and the error disappears.
Normal display:
OLS Regression Results
==============================================================================
Dep. Variable: close R-squared: 0.326
Model: OLS Adj. R-squared: 0.326
Method: Least Squares F-statistic: 1932.
Date: Tue, 22 Jan 2019 Prob (F-statistic): 0.00
Time: 14:34:33 Log-Likelihood: -11706.
No. Observations: 4000 AIC: 2.342e+04
Df Residuals: 3998 BIC: 2.343e+04
Df Model: 1
Covariance Type: nonrobust
==============================================================================
coef std err t P>|t| [0.025 0.975]
------------------------------------------------------------------------------
const 6.8217 0.092 74.332 0.000 6.642 7.002
close 0.3305 0.008 43.951 0.000 0.316 0.345
==============================================================================
Omnibus: 786.494 Durbin-Watson: 0.009
Prob(Omnibus): 0.000 Jarque-Bera (JB): 1384.316
Skew: 1.260 Prob(JB): 2.51e-301
Kurtosis: 4.399 Cond. No. 15.7
==============================================================================
Read More:
- Tensorflow error: InvalidArgumentError: indices[data_index] = data_value is not in [0, max_embedding_size)
- [Solved] Opencv Compile Error: (CMake Error: The following variables are used in this project, but they are set to not)
- Tensorflow C++:You must define TF_LIB_GTL_ALIGNED_CHAR_ARRAY for your compiler
- [Solved] Overleaf Compile the Paper Error: LaText Error:Environment aligned undefined.
- [Solved] MindSpore Error: ValueError: Minimum inputs size 0 does not match…
- AUC Error – ValueError: Data is not binary and pos_label is not specified
- [Solved] R Language Error: duplicate ‘row.names’ are not allowed
- Error: Comments are not permitted in JSON [How to Solve]
- Widgets are not available. Please install widgetsnbextension or ipywidgets 4.0
- ERROR: dependencies ‘curl’, ‘openssl’ are not available for package ‘httr’
- [Solved] MindSpore Error: “ValueError:invalid literal for int()with base10’the’
- Grpc Compilation issues: “C++ versions less than C++11 are not supported.
- [Solved] MindSpore Error: ValueError: For ‘AvgPool’ every dimension of the output shape must be greater than zero
- ValueError: Floating point image RGB values must be in the 0..1 range.
- [Solved] Tensorflow/Keras Error reading weights: ValueError: axes don‘t match array
- ValueError: Negative dimension size caused by subtracting 2 from 1 for…
- [Solved] MindSpore Error: ValueError: `padding_idx` in `Embedding` out of range
- Seaborn Color ValueError: Invalid RGBA argument: [‘#f9802d‘, ‘#f26b15‘, ‘#fdc48f‘]
- bazel Compile Error: absl/base/policy_checks.h:79:2: error: #error “C++ versions less than C++14 are not supported.”
- ValueError: Input 0 of node import/save/Assign was passed float from import/beta1_power:0 incompatib