Hello,
I have the code below:
clear
python:
from sklearn.naive_bayes import MultinomialNB
from sklearn.model_selection import GridSearchCV
from sklearn.model_selection import train_test_split
from sklearn import metrics # import scikit-learn metrics module for accuracy calculation
from sfi import Data
from sfi import Macro
import numpy as np
import pandas as pd
parameters = [{'alpha':np.linspace(0.1,4.6,10)}]
# right now the parameter is a list of dictionary that stores a numpy array
# the code below extracts the numpy array stored under the name 'alpha' and
# converts the numpy array into a python list before exporting it on stata
alpha_grid = parameters[0]['alpha'].tolist()
# export alpha_grid as a Stata variable
Data.setObsTotal(len(alpha_grid))
Data.addVarFloat('alphaGrid')
Data.store(var = 'alphaGrid', obs = None, val = alpha_grid)
end // end python mode
and I am trying to use the foreach loop on Stata with the line below:
foreach a1 of numlist alphaGrid {
...
}
however, doing so causes an error --- on my Stata window, the variable description appears to be that the variable 'alphaGrid' is a float type, and I am not sure why this line is causing an error.
The error is 'invalid numlist'
How can I resolve this issue?
Thank you,
I have the code below:
clear
python:
from sklearn.naive_bayes import MultinomialNB
from sklearn.model_selection import GridSearchCV
from sklearn.model_selection import train_test_split
from sklearn import metrics # import scikit-learn metrics module for accuracy calculation
from sfi import Data
from sfi import Macro
import numpy as np
import pandas as pd
parameters = [{'alpha':np.linspace(0.1,4.6,10)}]
# right now the parameter is a list of dictionary that stores a numpy array
# the code below extracts the numpy array stored under the name 'alpha' and
# converts the numpy array into a python list before exporting it on stata
alpha_grid = parameters[0]['alpha'].tolist()
# export alpha_grid as a Stata variable
Data.setObsTotal(len(alpha_grid))
Data.addVarFloat('alphaGrid')
Data.store(var = 'alphaGrid', obs = None, val = alpha_grid)
end // end python mode
and I am trying to use the foreach loop on Stata with the line below:
foreach a1 of numlist alphaGrid {
...
}
however, doing so causes an error --- on my Stata window, the variable description appears to be that the variable 'alphaGrid' is a float type, and I am not sure why this line is causing an error.
The error is 'invalid numlist'
How can I resolve this issue?
Thank you,
Comment