Error when showing Logistic Regression results - tuples

When I try to run a logistic regression in Jupyter notebooks, I get the following error:
model=LogisticRegression()
scoring='accuracy'
results = cross_val_score(model, X, Y, cv=kfold, scoring=scoring)
print("Accuracy: %.3f (%.3f)") % (results.mean(), results.std())
TypeError: unsupported operand type(s) for %: 'NoneType' and 'tuple'

I believe you were just missing the most outer wrapping parens. Try this.
print(("Accuracy: %.3f (%.3f)") % (results.mean(), results.std()))

Related

Baron Error with Pyomo: NonLinearity Error in POW expression

I am trying to solve a nonlinear optimization problem in Pyomo with Baron.
The solving works fine when using solvers like ipopt, bonmin, couenne etc.
When using Baron I get the following error:
===========================================================================
BARON version 18.5.9. Built: WIN-64 Wed May 9 22:52:08 EDT 2018
BARON is a product of The Optimization Firm, LLC. http://www.minlp.com/
BARON: NonLinearity Error in POW expression
ERROR: Solver (baron) returned non-zero return code (9)
ERROR: See the solver log above for diagnostic information.
Traceback (most recent call last):
File "C:/Users/public.THREADRIPPER/Desktop/CGAM_SWP.py", line 602, in <module>
Results = opt.solve(comp, tee=True, keepfiles=True)
File "C:\Anaconda3\lib\site-packages\pyomo\opt\base\solvers.py", line 626, in solve
"Solver (%s) did not exit normally" % self.name)
pyutilib.common._exceptions.ApplicationError: Solver (baron) did not exit normally
Process finished with exit code 1
Any idea where the problem is?
Thanks!
I'm not sure how urgent the matter still is but I experienced the same issue as you. Actually, in the BARON.py file there is a note regarding this error message here (hope you can see my screenshot, for some reason I am not allowed to upload pictures).
Anyway, I experience the problem in a different way than noted in the BARON.py file. In my case I am using the pyomo.core.base.symbolic.differentiate() function to create first derivates of functions which are to the power of (1/3) which then result in negative exponents which baron apparently has issues with. If I manually exchange the negative exponents with division, it seems to work.
Hope this helps you.
UPDATE: I have to update my comment because it is not negative exponents (per se) which in my case caused the error message of interest ("NonLinearity Error in POW expression", Solver (baron) returned non-zero return code (9)) but it is the way I had introduced them in the input file. In the baron manual there is an example of the case (see screenshot) I am referring to.
So in my case the error message was caused because I had constraints defined like this:
... * ( -241.5 + 0.5 * x12 ) ^ -1.0 * ( x1 - x6 ) ^ -1.0 * ( -483.0 + x12 + x1 - x6 ) ^ -1.0 * ...
which are according to the baron manual misinterpreted by the solver compared to my intention. Actually, in my case a x^y situation was created with nested negative exponential expressions which probably could be solved by baron if it is introduced differently (see next screenshot). However, if I include parentheses around the exponents, to get the expressions I am aiming for, i.e.:
... * ( -241.5 + 0.5 * x12 ) ^ (-1.0) * ( x1 - x6 ) ^ (-1.0) * ( -483.0 + x12 + x1 - x6 ) ^ (-1.0) * ...
it works perfectly fine.

set_xticklables() generates correct plot in DataFrame.plot but throws typeError in matplotlib for len()

Okay, so I have looked for the answer to my question, but cannot seem to find it. I am trying to make a bar chart with text labels using pandas and xticks on Python 2.7. this is the code I have. Here is the issue...it works as intended but throws an error:
fig=plt.figure(figsize=(25,9)) #creates figure object
fig.suptitle('Your Team\'s Check-in Performance', fontsize=20,fontweight='bold') #adds title layer
ax = fig.add_subplot(111) #add new subplot to figure
fig.subplots_adjust(top=0.85) #move down for subtitle
ax.set_title('Check-ins by Mentor') #add subtitle
ax.set_ylabel('Check-ins') #y label
ax.set_xlim(-1,38)
ax.grid()
ax.set_xticks(np.arange(0,37,1))
ax.set_xticklabels(mentor_checkin_ranks['Name'],rotation='vertical', fontsize=14,visible=True)
mentor_checkin_ranks.plot.bar(ax=ax,color='slategrey',xticks=ax.get_xticks)
Here is the error, it has to do with the interaction between 'matplotlib' and DataFrame.plot() sets the xticks on the axis:
/usr/local/lib/python2.7/dist-packages/matplotlib/axis.pyc in set_ticks(self, ticks, minor)
1595 # XXX if the user changes units, the information will be lost here
1596 ticks = self.convert_units(ticks)
-> 1597 if len(ticks) > 1:
1598 xleft, xright = self.get_view_interval()
1599 if xright > xleft:
TypeError: object of type 'instancemethod' has no len()
Any insight would be helpful, thanks a bunch , guys.
Update: changing xticks=ax.get_xticks to xticks=ax.get_xticks() fixes the error but removes the text labels. Changing to xticks=ax.get_xticklabels() works as intended but throws another error because the xticks are not floats.
Answered my own question, it was because pandas overwrote the ax.set_xticklabels() when I called Dataframe.plot.bar(). All I had to do was move it to the bottom and plt.show() afterward like this:
ax.set_xticks(np.arange(0,37,1))
mentor_checkin_ranks.plot.bar(ax=ax,color='slategrey',xticks=ax.get_xticks())
ax.set_xticklabels(mentor_checkin_ranks['Name'].values,rotation='vertical', fontsize=14)
plt.show()
And boom, it works and throws no errors.

Impala with Sas 9.4 : not import data with create table

creating a table with Sas and Impala I can't import data with many columns (more than 1500). The table is created but the data is not written and the following error is generated:
ERROR: CLI execute error: [Cloudera][ImpalaODBC] (110) Error while executing a query in Impala:
[HY000] : AnalysisException: Syntax error in line 1: ...,xxx`) VALUES ( ? , ? , ? , ? , ? , ? , ? , ...
^ Encountered: Unexpected character Expected: CASE, CAST, DEFAULT, EXISTS, FALSE, IF, INTERVAL, NOT, NULL, TRUNCATE, TRUE, IDENTIFIER
Thank you
I try to create a view or a table with engine SAS Impala (ODBC impala ClouderaImpalaODBC-2.5.36.1009-1.x86_64) RedHat 6.8. And I get this error:
ERROR: CLI execute error: [Cloudera] [ImpalaODBC] (110) Error while executing a query in Impala: [HY000]: AnalysisException: Syntax
error in line 1: ... King ((a.trns_dt between {d '31.10.2015'} and {d '^ 2 ... Encountered:
Unexpected character Expected: CASE, CAST, EXISTS, FALSE, IF, INTERVAL, NOT NULL, TRUNCATE, TRUE, IDENTIFIER Caused BY:
Exception: Syntax error
We have seen that characters that are passed impala can not read such. "{}".

Caculating average from some data with python 2.7.x

I have been practicing python to learn how to code and I'm making python program that calculates averages from numbers which are put in by users.
Here is codes
avg_input=0.0
import sys
input_list=sys.argv[1:]
for avg in input_list :
avg_input += avg
avg_input /= len(input_list)
avg_input
and this is error messages
Traceback (most recent call last):
File "exfor3.py", line 30, in <module>
avg_input += avg
TypeError: unsupported operand type(s) for +=: 'float' and 'str'
sys.argv is a list of strings. You need to convert these to numbers before adding them. Use:
avg_input += float(avg)
It seems you are trying to add a float value to a string. You will either need to convert the variable avg into a float using the float()function or change the variable type for avg

Doctrine 2 - COALESCE and CONCAT

I have this DQL Query:
$repository->createQuery("SELECT f.id, COALESCE(f.name,
CONCAT(f.floor_number, ' NP')) as name FROM ".__NAMESPACE__.'\\Floor f
WHERE f.building = ?1')
->setParameter(1, $this->building);
but it doesn't work - i get
[Syntax Error] line 0, col 36: Error: Expected Doctrine\ORM\Query\Lexer::T_CLOSE_PARENTHESIS, got '('
The reason is usage of CONCAT inside COALESCE.... is there any way how to make this work (without native query)?
This problem was fixed by an improvement to the DQL parser in Doctrine 2.4. Upgrade to 2.4 and this query will work.