How to solve 'numpy.float64' object is not callable - data-science

rsq_admin = smf.ols("Admin~RDS+MS", data=startup1).fit().rsquared()
vif_admin = 1/(1-rsq_admin)
I am trying to find the r-squared value to calculate VIF, but I am getting 'numpy.float64' object is not callable error
My dataset has Dtype as Float64

Related

Vpython Error: 'float' object has no attribute '_x'

I am writing a Vpython simulation for projectile motion and keep getting the error ('float' object has no attribute '_x') on this line(ball.vel.y = ball.vel.y + g*dt) . I have tried changing the values of ball.vel.y to an integer and changing g to an integer but the same error occurs. Here is the code
from vpython import *
import math
ball=sphere(radius=0.1, color=color.red, pos=vector(0.1,0.1,0),make_trail=True)
floor=box(pos=vector(0,0,0), length=10, height=0.01, width=0.01)
g= vector(0,-9.8 ,0)
ball.vel=vector(10*cos(43),10*sin(43),0)
dt=0.1
t=0.0
while(ball.pos.y>-0.001):
rate(100)
t=t+dt
ball.pos.x = ball.pos.x + ball.vel.x*dt
ball.vel.y = ball.vel.y + g*dt
ball.pos.y = ball.pos.y + ball.vel.y*dt
g is a vector, as is g*dt, but ball.vel.y is a scalar, and you can't add a vector to a scalar. It's unfortunate that the error message doesn't just say "You can't add a vector to a scalar". I note that if you reverse the two quantities the error message is a bit more understandable: TypeError: unsupported operand type(s) for +: 'vpython.cyvector.vector' and 'float'

Pandas 'Timestamp' object is not subscriptable error

I have a data frame and I am trying to figure our days of the week for a data set.
df['day_of_week'] = df['CMPLNT_TO_DT'].dt.day_name()
TypeError: 'Timestamp' object is not subscriptable
Your problem is with an incorrect assignment.
df['date']=pd.date_range('2021/5/9', '2021/5/14')
df['date'].dt.day_name()
Output:
and:
df = pd.Timestamp('2017-01-01T12')
df['CMPLNT_TO_DT'].dt.day_name()
Output:
The problem is not with the .dt.day_name():
df = pd.Timestamp('2017-01-01T12')
df['CMPLNT_TO_DT']
again:

TypeError: 'NoneType' object is not subscriptable when checking for nonetype

I am trying to detect Nonetype in a single cell of a 1 column, 15 row dataframe with the following:
if str(row.iloc[13][:]) is None:
print("YES")
But this causes the error: TypeError: 'NoneType' object is not subscriptable
If row is Series, then if select value by position:
row.iloc[13]
output is scalar. So cannot slice scalar value by [:]. Also if convert to string by str cannot compare by None, but by string like:
if str(row.iloc[13]) == 'None':
If want compare by None:
if row.iloc[13] is None:
Or if compare by NaN or None:
if pd.isna(row.iloc[13]):

converting pyspark dataframe fail on 'None Type' object

I have a pyspark dataframe 'data3' with many columns. I am trying to run kmeans on it except the first two columns, when I run my code , tasks always fails on TypeError: float() argument must be a string or a number, not 'NoneType' What am I doing wrong?
def f(x):
rel = {}
#rel['features'] = Vectors.dense(float(x[0]),float(x[1]),float(x[2]),float(x[3]))
rel['features'] = Vectors.dense(float(x[2]),float(x[3]),float(x[4]),float(x[5]),float(x[6]),float(x[7]),float(x[8]),float(x[9]),float(x[10]),float(x[11]),float(x[12]),float(x[13]),float(x[14]),float(x[15]),float(x[16]),float(x[17]),float(x[18]),float(x[19]),float(x[20]),float(x[21]),float(x[22]),float(x[23]),float(x[24]),float(x[25]),float(x[26]),float(x[27]),float(x[28]),float(x[29]),float(x[30]),float(x[31]),float(x[32]),float(x[33]),float(x[34]),float(x[35]),float(x[36]),float(x[37]),float(x[38]),float(x[39]),float(x[40]),float(x[41]),float(x[42]),float(x[43]),float(x[44]),float(x[45]),float(x[46]),float(x[47]),float(x[48]),float(x[49]))
return rel
data= data3.rdd.map(lambda p: Row(**f(p))).toDF()
kmeansmodel = KMeans().setK(7).setFeaturesCol('features').setPredictionCol('prediction').fit(data)
TypeError: float() argument must be a string or a number, not 'NoneType'
Your error comes from converting the xs to float because you probably have missing values
rel['features'] = Vectors.dense(float(x[2]),float(x[3]),float(x[4]),float(x[5]),float(x[6]),float(x[7]),float(x[8]),float(x[9]),float(x[10]),float(x[11]),float(x[12]),float(x[13]),float(x[14]),float(x[15]),float(x[16]),float(x[17]),float(x[18]),float(x[19]),float(x[20]),float(x[21]),float(x[22]),float(x[23]),float(x[24]),float(x[25]),float(x[26]),float(x[27]),float(x[28]),float(x[29]),float(x[30]),float(x[31]),float(x[32]),float(x[33]),float(x[34]),float(x[35]),float(x[36]),float(x[37]),float(x[38]),float(x[39]),float(x[40]),float(x[41]),float(x[42]),float(x[43]),float(x[44]),float(x[45]),float(x[46]),float(x[47]),float(x[48]),float(x[49]))
return rel
You can create a flag to convert each x to float when there is a missing values. For example
list_of_Xs = [x[2], x[3], x[4], x[5], x[6],etc. ]
for x in list_of_Xs:
if x is not None:
x = float(x)
Or use rel.dropna()

Failed to convert object of type <class 'function'> to Tensor

I am trying to randomize the flip augmentation using tensorflow's left_right and up_down augmentation function. I am getting error mapping the function based on the boolean condition via tf.cond()
random_number=tf.random_uniform([],seed=seed)
print_random_number=tf.print(random_number)
flip_strategy=tf.less(random_number,0.5)
version 0.1
image=tf.cond
(
flip_strategy,
tf.image.flip_left_right(image),
tf.image.flip_up_down(image),
)
version 0.2
image=tf.cond
(
flip_strategy,
lambda: tf.image.flip_left_right(image),
lambda: tf.image.flip_up_down(image),
)
ERROR
TypeError: Failed to convert object of type to Tensor. Contents: . Consider casting elements to a supported type.ROR:
Let me know what am I missing or if more info is needed.
From the documentation:
tf.math.less(
x,
y,
name=None
)
Args:
x: A Tensor. Must be one of the following types: float32, float64, int32, uint8, int16, int8, int64, bfloat16, uint16, half, uint32, uint64.
y: A Tensor. Must have the same type as x.
name: A name for the operation (optional).
So tf.less expects two tensors, but one of the arguments you pass is a numpy array. You could just convert the numpy array in tensor like
random_number=tf.random_uniform([],seed=seed)
print_random_number=tf.print(random_number)
random_numer=tf.convert_to_tensor(random_number,dtype=tf.float32)
flip_strategy=tf.less(random_number,0.5)
image=tf.cond`
(
flip_strategy,
tf.image.flip_left_right(image),
tf.image.flip_up_down(image),
)