Im using following code to train my model
trip_model = sm.OLS(x_dependent, y_variables).fit()
and print summary as
trip_model.summary()
I just want to take only the following values out of Summary
F-statistic , coef
how to get it?
The value returned by the fit function is a RegressionResults structure. You can check the documentation to see how to access each particular value:
f_statistic = trip_model.fvalue
coef = trip_model.params
Related
I have a #transform_pandas code which loads the input file for computing.
Inside the compute function I have a for loop which has to read the complete input data and filter accordingly for every iteration.
#transform_pandas(
Output("/FCA_Foundry/dataset1"),
source_df=Input(sample),
)
I have the below code where I'm trying to read source_df dataset for every iteration in for loop and filter the dataset specifically to the year and family and do the computation.
def compute(source_df):
for entire_row in vhcl_df.itertuples():
modyr = entire_row[1]
fam = str(entire_row[2])
/* source_df should be read again here.
source_df = source_df.loc[source_df['i_yr']==modyr]
source_df = source_df.loc[source_df['fam']==fam]
...
Is there a way to achieve this. Thank you for your support.
As already suggested by #nicornk in the comments, you should create a new .copy() item of your source_df right after you declare the transform.
The two filtering steps (that can ben also merged in one, if you don't need to work just on the "modyr filtered" source_df.
Please note that modyr, fam are actual colnames of vhcl_df, it is actually sufficient to
#transform_pandas(
Output("/FCA_Foundry/dataset1"),
source_df=Input(sample),
vhcl_df=Input(path)
)
def compute(source_df, vhcl_df):
for modyr, fam in vhcl_df.items():
temp_df = source_df.copy()
temp_df = source_df.loc[source_df['i_yr']==modyr]
temp_df = source_df.loc[source_df['fam']==str(fam)]
which, in a more concise and clean way is actually writable as
def compute(source_df, vhcl_df):
for modyr, fam in vhcl_df.items():
temp_df = source_df.copy()
filtered_temp_df = temp_df[(temp_df.i_yr==modyr) & (temp_df.fam==str(fam))]
PS: Remember that if source_df is big, you should proceed with PySpark (see foundry docs)
Note that transform_pandas should only be used on datasets that can fit into memory. If you have larger datasets that you wish to filter down first before converting to Pandas, you should write your transformation using the transform_df() decorator and the pyspark.sql.SparkSession.createDataFrame() method.
There are the following attributes in client_output
weights_delta = attr.ib()
client_weight = attr.ib()
model_output = attr.ib()
client_loss = attr.ib()
After that, I made the client_output in the form of a sequence through
a = tff.federated_collect(client_output) and round_model_delta = tff.federated_map(selecting_fn,a)in here . and I declared
`
#tff.tf_computation() # append
def selecting_fn(a):
#TODO
return round_model_delta
in here. In the process of averaging on the server, I want to average the weights_delta by selecting some of the clients with a small loss value. So I try to access it via a.weights_delta but it doesn't work.
The tff.federated_collect returns a tff.SequenceType placed at tff.SERVER which you can manipulate the same way as for example client dataset is usually handled in a method decorated by tff.tf_computation.
Note that you have to use the tff.federated_collect operator in the scope of a tff.federated_computation. What you probably want to do[*] is pass it into a tff.tf_computation, using the tff.federated_map operator. Once inside the tff.tf_computation, you can think of it as a tf.data.Dataset object and everything in the tf.data module is available.
[*] I am guessing. More detailed explanation of what you would like to achieve would be helpful.
Just like in MySQL query where we retrieve columns with conditions using WHERE clause, how can we do the same in Python? That too with a CSV file?
My CSV File contains data with attributes Name, Place and Color
Ruby,NewYork,Green
Casper,Seoul, Blue
Caroline,NewYork,Green
Now user is given choice to provide city and color name for search. If user input: City = NewYork and Color= Green, It should display
Ruby
Caroline.
How should I do it? I wrote a sample code but output is wrong.
import csv
class Test:
def Display(Name,Place,Color):
f = open('sample.csv')
csv_f = csv.reader(f)
for row in csv_f:
if(row[1]==("NewYork") and row[2] ==("Green")):
pass
print(Name)
Name,Place,Color = input("Enter Details: ").split()
Test.Display(Name,Place,Color)
Consider the following test object:
import csv
class Test:
def display(self, name, place, color):
with open('sample.csv') as csv_file:
csv_reader = csv.reader(csv_file, delimiter=',')
for row in csv_reader:
if(row[1]==place and row[2] == color):
print(row[0])
test = Test()
test.display("Name","NewYork","Green")
We have a Class with a member function for displaying the output.
You can first open the csv file and use the csv_file reference to create your reader in scope. Then you search each row's column for the given strings that you passed into the function.
It looks like you got into a bit of trouble trying to diagnose this one and have left test code in there that has been confusing you.
#api.depends('totalbook')
def _computebook(self):
sum_a = 0
for rec in self:
for l in rec.env['book.tickets'].search([('status', 'in', ('sold', 'rent'))]):
if l:
sum_a += 1
rec.currentbook = rec.totalbook - sum_a
I use this compute to calculate current book in library.
But when I run this code, the problem calculate of my each book base on all books.
When you are write any compute method in odoo, in self you will get all the list of browsable objects.
And then you are trying to search data from that browsable object. That's why you get a error.
You have to use self.env instead of rec.env.
Because you can't search data from browsable object you can access only data of that browsable object.
You have to add limit 1 on when you are searching a record of multiple record are than you will get another expected Singleton error.
Either you can you use another loop after searching record.
Let me know if you face any errors again.
Thanks
this error occured because
whenever you are trying to make a object of another model at that time you should have to use with self.env instead of rec.env because in your method rec is just a record-set of your instance
so please update your method as per the following snippet.
for l in self.env['book.tickets'].search([('status', 'in', ('sold','rent'))]):
I am using Encog in one of the project and i got stuck while deocding One-Of class.
One of the field's Normalization Action is NormalizationAction.OneOf which have three output. When i evaluate, i want to decode the predicted value. how to decode...?
var eq = new Encog.MathUtil.Equilateral(classCount, normalizationHigh, normalizationLow);
var predictedClassInt = eq.Decode(output);
The above code is for Equilateral. How can i do the same for One-Of.
Thanks,
Kans
Here is sample code (in C#) for decoding one-of-n encoded classes.
var outputIndex = EngineArray.MaxIndex(output);
var classOutput = analyst.Script.Normalize.NormalizedFields[index].Classes[outputIndex].Name;
Means,you get the output array using Network.Compute() first.Then you try to find out, which element in the output array has the maximum value (The Winner). Then you can use that index and the analyst information to get the class name.
So you can use your analyst class. If you have persisted you analyst file, then you can load it to memory using
var analyst = new EncogAnalyst();
analyst.Load(AnalystFilePath.ToString());