Open xiangqingcs opened 1 year ago
Pandas method of corr:
def corr(self, other, method="pearson", min_periods=None) -> float:
"""
Compute correlation with `other` Series, excluding missing values.
Parameters
----------
other : Series
Series with which to compute the correlation.
method : {'pearson', 'kendall', 'spearman'} or callable
Method used to compute correlation:
- pearson : Standard correlation coefficient
- kendall : Kendall Tau correlation coefficient
- spearman : Spearman rank correlation
- callable: Callable with input two 1d ndarrays and returning a float.
.. warning::
Note that the returned matrix from corr will have 1 along the
diagonals and will be symmetric regardless of the callable's
behavior.
min_periods : int, optional
Minimum number of observations needed to have a valid result.
Returns
-------
float
Correlation with other.
See Also
--------
DataFrame.corr : Compute pairwise correlation between columns.
DataFrame.corrwith : Compute pairwise correlation with another
DataFrame or Series.
Examples
--------
>>> def histogram_intersection(a, b):
... v = np.minimum(a, b).sum().round(decimals=1)
... return v
>>> s1 = pd.Series([.2, .0, .6, .2])
>>> s2 = pd.Series([.3, .6, .0, .1])
>>> s1.corr(s2, method=histogram_intersection)
0.3
"""
this, other = self.align(other, join="inner", copy=False)
if len(this) == 0:
return np.nan
if method in ["pearson", "spearman", "kendall"] or callable(method):
return nanops.nancorr(
this.values, other.values, method=method, min_periods=min_periods
)
raise ValueError(
"method must be either 'pearson', "
"'spearman', 'kendall', or a callable, "
f"'{method}' was supplied"
)
How do you add multiple arguments to an operator in Qlib ops?
Such as the following parameters with method of corr.
method="pearson", min_periods=None
🌟 Feature Description
project version: 0.8.6 Python version: 3.8 pandas version: 1.3.4 numpy version: 1.21.4
Code Loaction: qlib\data\ops.py L1439 -- L1470 L1458
Code Loaction: qlib\data\ops.py L1387 -- L1405 L1404
The core code is as follows:
series = getattr(series_left.rolling(self.N, min_periods=1), self.func)(series_right)
I wrote my own validation code
Computational Results:
Conclusion:
### The above code of
getattr(series_left.rolling(6, min_periods=1), "corr")(series_right, "spearman")
has no effect with params of 'spearman', How do I fix this?Motivation
Alternatives
Additional Notes