我有一个包含不同表(结构都相同)的数据库,我想在其中运行一个存储过程,该过程具有一个定义要查询哪个表的参数。
我似乎无法弄清楚:
CREATE SCHEMA test;
GO
Run Code Online (Sandbox Code Playgroud)
首先我创建了一个架构
CREATE TYPE DataType as TABLE (
[datetime] [datetime] NULL,
[testVar] [bigint] NULL)
GO
Run Code Online (Sandbox Code Playgroud)
然后我创建了表类型
USE [TestDataFiles]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [test].[testing]
(
-- Add the parameters for the stored procedure here
@datetime datetime,
@t DataType READONLY
)
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON
select top(10) *
from @t
where [datetime] > …Run Code Online (Sandbox Code Playgroud) 我将dput列表的底部放在底部,以便q可以重现。dput是anot x。
我有一个很大的嵌套列表x,我试图从中构建数据框,但无法弄清楚。
我已经完成了第一部分:
for(i in 1:3){a[[i]]<-x$results[[i]]$experiences
indx <- lengths(a)
zz <- as.data.frame(do.call(rbind,lapply(a, `length<-`, max(indx))))}
Run Code Online (Sandbox Code Playgroud)
为此,我使用以下答案: 将嵌套列表(长度不等)转换为数据帧
这给我留下了一个带有n列的data.frame作为结果,其中n是任何i的最大结果:
v1 v2 v3
1 NULL NULL NULL
2 * * *
3 NULL NULL NULL
Run Code Online (Sandbox Code Playgroud)
每个*是另一个嵌套列表,格式为 list(experience = list(duration = ...
例如,第*2行第v1列。我不要总数。我只想要:
a[[2]][[1]]$experience$start
Run Code Online (Sandbox Code Playgroud)
或就原始列表而言:
x$results[[2]]$experiences[[1]]$experience$start
Run Code Online (Sandbox Code Playgroud)
我觉得我快要调整了。我试过了:
for(i in 1:3){a[[i]]<-x$results[[i]]$experiences
indx <- lengths(a)
for(y in 1:length(a[[i]])) aa <- rbind(aa,tryCatch(x$results[[i]]$experiences[[y]]$experience$start, error=function(e) print(NA)))
zz <- as.data.frame(do.call(rbind,lapply(aa, `length<-`, max(indx))))}
Run Code Online (Sandbox Code Playgroud)
导致:
v1 v2 v3
1 NA NA NA …Run Code Online (Sandbox Code Playgroud) In R there is a function called assign which assigns a value to a name in the environment.
EG:
assign("Hello", 2)
> Hello
[1] 2
Run Code Online (Sandbox Code Playgroud)
In python I can't seem to do the same. I initially tried:
import numpy as np
import pandas as pd
import os
for file in os.listdir('C:\\Users\\Olivia\\Documents'):
if file.endswith(".csv"):
os.path.splitext(file)[0] = pd.read_csv('C:\\Users\\Olivia\\Documents\\' + file)
Run Code Online (Sandbox Code Playgroud)
But I can see this is trying to make a string equal to a file which doesn't work.
I managed to get …
我想根据新近度为我的训练数据添加权重。
如果我们看一个简单的例子:
import matplotlib.pyplot as plt
import numpy as np
from sklearn.preprocessing import PolynomialFeatures, normalize
from sklearn.linear_model import LinearRegression
X = np.array([1,2,3,4,5,6,7,8,9,10]).reshape(-1,1)
Y = np.array([0.25, 0.5, 0.75, 1, 1.5, 2, 3, 4, 6, 10]).reshape(-1,1)
poly_reg = PolynomialFeatures(degree=2)
X_poly = poly_reg.fit_transform(X)
pol_reg = LinearRegression()
pol_reg.fit(X_poly, Y)
plt.scatter(X, Y, color='red')
plt.plot(X, pol_reg.predict(poly_reg.fit_transform(X)), color='blue')
Run Code Online (Sandbox Code Playgroud)
现在假设 X 值是基于时间的,而 Y 值是传感器的快照。所以我们正在对一些行为进行建模。我相信最新的数据点是最重要的,因为它们是最新的,并且最能代表未来的行为。我想调整我的模型,使最新的数据点权重最高。
在 R 中有一个关于这样做的问题:https : //stats.stackexchange.com/questions/196653/assigning-more-weight-to-more-recent-observations-in-regression
我想知道 sklearn 包(或任何其他 python 包)是否具有此功能?
此加权模型将具有类似的曲线,但会更好地拟合较新的点。如果我想用这个模型来预测未来,非加权模型的预测总是过于保守,因为它们对最新数据不那么敏感。
除了使用这种方法,我还使用了 curve_fit 来使用幂函数或指数函数:
from scipy.optimize import curve_fit
def func(x, a, b):
return …Run Code Online (Sandbox Code Playgroud) 我想将列表更改为数据框的一个单元格。
list <- list(1,2,3,4,5)
View(list)
[[1]]
[1] 1
[[2]]
[1] 2
[[3]]
[1] 3
[[4]]
[1] 4
[[5]]
[1] 5
Run Code Online (Sandbox Code Playgroud)
我想对其进行改造,使其看起来像:
x
1 1,2,3,4,5
Run Code Online (Sandbox Code Playgroud)
原因是因为我有一个循环将每次迭代的结果存储在列表中,但每次迭代我只需要一个单元格。
还有其他列,每次迭代只有一个结果。因此将其保存在数据框中很容易。但对于具有多个结果的指标,我不需要多列或多行。
因此,我将有两个可以使用的数据框cbind,这样我的最终数据框将如下所示:
x y
1 1,2,3,4,5 a
2 5,4,3 b
Run Code Online (Sandbox Code Playgroud) dataframe ×2
list ×2
python ×2
r ×2
assign ×1
loops ×1
pandas ×1
regression ×1
scikit-learn ×1
sql-server ×1
user-defined ×1
weighted ×1