Skip to main content

Error on Seaborn lmplot when passing dataframe data due to dtype('O') error, except I've replaced all object dtypes [duplicate]

Background

I have a dataframe imported from an excel doc. Each column is an experiment variable and every row is an entry. The dataframe is 242x18.

I am attempting to plot 1x3 lmplot, plotting two Float64 dtypes against one another. Data shown below for context: Data in question dtypes of data

Here are the dtypes of the full dataframe: dtypes of full dataframe

Note that it was read in as: dtypes of full dataframe prior to conversion

Where I then used:

df = df_forging.convert_dtypes()

The Error

The function I'm using is exactly:

g = sns.lmplot(data = df,y='Peak Tensile Force (N)',x='Elliptical Area (mm^2)') 

Which returns the following:


---------------------------------------------------------------------------

UFuncTypeError                            Traceback (most recent call last)
>! \~\\AppData\\Local\\Temp\\ipykernel_27312\\4132946937.py in \<module\>
1 # Isolate to one weld population
2 g = sns.lmplot(data=df_forging,
3                y='Peak Tensile Force (N)',
4                x='Elliptical Area (mm^2)'
5                # hue='Weld Population',

C:\\ProgramData\\Anaconda3\\lib\\site-packages\\seaborn\\regression.py in lmplot(data, x, y, hue, col, row, palette, col_wrap, height, aspect, markers, sharex, sharey, hue_order, col_order, row_order, legend, legend_out, x_estimator, x_bins, x_ci, scatter, fit_reg, ci, n_boot, units, seed, order, logistic, lowess, robust, logx, x_partial, y_partial, truncate, x_jitter, y_jitter, scatter_kws, line_kws, facet_kws)
633         scatter_kws=scatter_kws, line_kws=line_kws,
634     )
635     facets.map_dataframe(regplot, x=x, y=y, \*\*regplot_kws)
636     facets.set_axis_labels(x, y)
637

C:\\ProgramData\\Anaconda3\\lib\\site-packages\\seaborn\\axisgrid.py in map_dataframe(self, func, \*args, \*\*kwargs)
817
818             # Draw the plot
819             self.\_facet_plot(func, ax, args, kwargs)
820
821         # For axis labels, prefer to use positional args for backcompat

C:\\ProgramData\\Anaconda3\\lib\\site-packages\\seaborn\\axisgrid.py in \_facet_plot(self, func, ax, plot_args, plot_kwargs)
846             plot_args = \[\]
847             plot_kwargs\["ax"\] = ax
848         func(\*plot_args, \*\*plot_kwargs)
849
850         # Sort out the supporting information

C:\\ProgramData\\Anaconda3\\lib\\site-packages\\seaborn\\regression.py in regplot(data, x, y, x_estimator, x_bins, x_ci, scatter, fit_reg, ci, n_boot, units, seed, order, logistic, lowess, robust, logx, x_partial, y_partial, truncate, dropna, x_jitter, y_jitter, label, color, marker, scatter_kws, line_kws, ax)
757     scatter_kws\["marker"\] = marker
758     line_kws = {} if line_kws is None else copy.copy(line_kws)
759     plotter.plot(ax, scatter_kws, line_kws)
760     return ax
761

C:\\ProgramData\\Anaconda3\\lib\\site-packages\\seaborn\\regression.py in plot(self, ax, scatter_kws, line_kws)
366
367         if self.fit_reg:
368             self.lineplot(ax, line_kws)
369
370         # Label the axes

C:\\ProgramData\\Anaconda3\\lib\\site-packages\\seaborn\\regression.py in lineplot(self, ax, kws)
411         """Draw the model."""
412         # Fit the regression model
413         grid, yhat, err_bands = self.fit_regression(ax)
414         edges = grid\[0\], grid\[-1\]
415

C:\\ProgramData\\Anaconda3\\lib\\site-packages\\seaborn\\regression.py in fit_regression(self, ax, x_range, grid)
217             yhat, yhat_boots = self.fit_logx(grid)
218         else:
219             yhat, yhat_boots = self.fit_fast(grid)
220
221         # Compute the confidence interval at each grid point

C:\\ProgramData\\Anaconda3\\lib\\site-packages\\seaborn\\regression.py in fit_fast(self, grid)
234         X, y = np.c\_\[np.ones(len(self.x)), self.x\], self.y
235         grid = np.c\_\[np.ones(len(grid)), grid\]
236         yhat = grid.dot(reg_func(X, y))
237         if self.ci is None:
238             return yhat, None

C:\\ProgramData\\Anaconda3\\lib\\site-packages\\seaborn\\regression.py in reg_func(\_x, \_y)
230         """Low-level regression and prediction using linear algebra."""
231         def reg_func(\_x, \_y):
232             return np.linalg.pinv(\_x).dot(_y)
233
234         X, y = np.c_\[np.ones(len(self.x)), self.x\], self.y

C:\\ProgramData\\Anaconda3\\lib\\site-packages\\numpy\\core\\overrides.py in pinv(\*args, \*\*kwargs)

C:\\ProgramData\\Anaconda3\\lib\\site-packages\\numpy\\linalg\\linalg.py in pinv(a, rcond, hermitian)
1996         return wrap(res)
1997     a = a.conjugate()
1998     u, s, vt = svd(a, full_matrices=False, hermitian=hermitian)
1999
2000     # discard small singular values

C:\\ProgramData\\Anaconda3\\lib\\site-packages\\numpy\\core\\overrides.py in svd(\*args, \*\*kwargs)

C:\\ProgramData\\Anaconda3\\lib\\site-packages\\numpy\\linalg\\linalg.py in svd(a, full_matrices, compute_uv, hermitian)
1655
1656         signature = 'D-\>DdD' if isComplexType(t) else 'd-\>ddd'
1657         u, s, vh = gufunc(a, signature=signature, extobj=extobj)
1658         u = u.astype(result_t, copy=False)
1659         s = s.astype(\_realType(result_t), copy=False)

UFuncTypeError: Cannot cast ufunc 'svd_n_s' input from dtype('O') to dtype('float64') with casting rule 'same_kind'

What I've tried

As mentioned above, I fixed all the dtypes to better fit the contained data. I have used the same dataset with seaborn.scatterplot, which worked without error.

I think the issue is that it think it's seeing an dtype('O'), but I don't see how that can be.



source https://stackoverflow.com/questions/75546110/error-on-seaborn-lmplot-when-passing-dataframe-data-due-to-dtypeo-error-exc

Comments

Popular posts from this blog

ValueError: X has 10 features, but LinearRegression is expecting 1 features as input

So, I am trying to predict the model but its throwing error like it has 10 features but it expacts only 1. So I am confused can anyone help me with it? more importantly its not working for me when my friend runs it. It works perfectly fine dose anyone know the reason about it? cv = KFold(n_splits = 10) all_loss = [] for i in range(9): # 1st for loop over polynomial orders poly_order = i X_train = make_polynomial(x, poly_order) loss_at_order = [] # initiate a set to collect loss for CV for train_index, test_index in cv.split(X_train): print('TRAIN:', train_index, 'TEST:', test_index) X_train_cv, X_test_cv = X_train[train_index], X_test[test_index] t_train_cv, t_test_cv = t[train_index], t[test_index] reg.fit(X_train_cv, t_train_cv) loss_at_order.append(np.mean((t_test_cv - reg.predict(X_test_cv))**2)) # collect loss at fold all_loss.append(np.mean(loss_at_order)) # collect loss at order plt.plot(np.log(al...

Sorting large arrays of big numeric stings

I was solving bigSorting() problem from hackerrank: Consider an array of numeric strings where each string is a positive number with anywhere from to digits. Sort the array's elements in non-decreasing, or ascending order of their integer values and return the sorted array. I know it works as follows: def bigSorting(unsorted): return sorted(unsorted, key=int) But I didnt guess this approach earlier. Initially I tried below: def bigSorting(unsorted): int_unsorted = [int(i) for i in unsorted] int_sorted = sorted(int_unsorted) return [str(i) for i in int_sorted] However, for some of the test cases, it was showing time limit exceeded. Why is it so? PS: I dont know exactly what those test cases were as hacker rank does not reveal all test cases. source https://stackoverflow.com/questions/73007397/sorting-large-arrays-of-big-numeric-stings

How to load Javascript with imported modules?

I am trying to import modules from tensorflowjs, and below is my code. test.html <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title </head> <body> <script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs@2.0.0/dist/tf.min.js"></script> <script type="module" src="./test.js"></script> </body> </html> test.js import * as tf from "./node_modules/@tensorflow/tfjs"; import {loadGraphModel} from "./node_modules/@tensorflow/tfjs-converter"; const MODEL_URL = './model.json'; const model = await loadGraphModel(MODEL_URL); const cat = document.getElementById('cat'); model.execute(tf.browser.fromPixels(cat)); Besides, I run the server using python -m http.server in my command prompt(Windows 10), and this is the error prompt in the console log of my browser: Failed to loa...