How to prevent Jupyter Notebook from cutting output? - jupyter-notebook

When I print, for some reason Jupyter cuts some text out of the middle of output ( perhaps to make it more readable), but I need to see it.
What are the possible solutions?
Is there any option I can change in Jupyter to prevent if from cutting?
P.S. Sorry can't embed images yet. Use the link, thx.
enter image description here
my_pipeline = make_pipeline(ce.OneHotEncoder(use_cat_names=True),
SimpleImputer(),
XGBRegressor(n_estimators=1000,
learning_rate=0.01,
clf__early_stopping_rounds=10,
clf__eval_set=[(test_X, test_y)],
random_state=45,
verbose=True))
# fitting and predicting
print(my_pipeline.fit(train_X, train_y))
predictions = my_pipeline.predict(test_X)
print("Mean Absolute Error : " + str(mean_absolute_error(predictions,
test_y)))
OUTPUT:
Pipeline(memory=None,
steps=[('onehotencoder', OneHotEncoder(cols=['Neighborhood'], drop_invariant=False,
handle_unknown='impute', impute_missing=True, return_df=True,
use_cat_names=True, verbose=0)), ('simpleimputer', SimpleImputer(copy=True, fill_value=None, missing_values=nan, strategy='mean',
ver... reg_lambda=1, scale_pos_weight=1, seed=None, silent=True,
subsample=1, verbose=True))])
As you see on the OUTPUT by the "ver..." - it is cut. Thx.

Related

How to find a file with python with Ã

im working on a mtg auto sorter and some of the cards have interesting names that python seems to not want to find. i am looking for a file (that i know i have in the right spot) called 8_JÃtun_Grunt.png. using this...
for card_name in card_names:
# Fetch the image - name can be found based on the card's information
card_info['name'] = card_name
img_name = '%s/card_img/png/%s/%s_%s.png' % (Config.data_dir, card_info['set'],
card_info['collector_number'],
fetch_data.get_valid_filename(card_info['name']))
card_img = cv2.imread(img_name)
# If the image doesn't exist, download it from the URL
if card_img is None:
fetch_data.fetch_card_image(card_info,
out_dir='%s/card_img/png/%s' % (Config.data_dir, card_info['set']))
card_img = cv2.imread(img_name)
if card_img is None:
print('WARNING: card %s is not found!' % img_name)
the error i get is so
error from cmd
this leads me to think that it cant recognize the file name but im reading it from a database that i cant change. any ideas.
I wouldn't be surprised if OpenCV couldn't handle filepaths with unicode caracters.
you could try to add the code from the answer of this SO question

tradingview pine script error "cannot use 'plot' in a local scope"

I am trying to write a simple if-then-else statement using the Pine language under Tradingview. What the code does is based upon user input.
If the box is checked, the plot the line.
If the box is not checked do not plot the line.
This is the code I have:
notPlot = -2000
var ch382= input(true, ".382")
if ch382
plot( ch382? bottom + diff * .382: noPlot, title="fib-.236", linewidth=3, color=color.orange )
How can I write this in a proper way?
If I try to run it, I get: “cannot use 'plot' in a local scope”
Any assistance would be greatly appreciated.
ETA: I found this thread below
How to put plot statement inside if statement
but -
what I need to do is to plot if the box is checked and ~not plot~ if the box is not checked.
ETA: figured out the issue. One would use "na" (in the case of plotting) to note that the line should not be displayed - my mistake ...
var ch382 = input(true, ".382")
plot( ch382? bottom + diff * .382: na, title="fib-.382", linewidth=3, color=color.orange )

RStudio keyboard shortcut to wrap / unwrap code in parentheses?

Sometimes it's preferable to wrap commands in ( and ) so that the output prints to console
Random example:
(logical_sample <- c(0,1,0,1,0,1,0,1,0))
(sample_mean <- mean(logical_sample))
(sample_st_deviation <- sd(logical_sample))
(n <- length(logical_sample))
Is there a quick RStudio keyboard shortcut for un/parenthesising the same way we can use command + shift + c to un/comment?
According to the official list...
As you can see on the official RStudio Keyboard Shortcuts list (link here) there is none, but you can use Ctrl + P to jump to the matching parenthesising, which can help speed things up.
Hope this helps.

How to suppress unwanted Plot figure object information in Jupyter Notebook

I want to suppress any text output when I run Jupyter Notebook cell. Specifically I output some figures and each is accompanied by something like:
<Figure size 432x288 with 0 Axes>
I have seen that if I put a ; at the end of a line, it should suppress the output, but it is not working in my case.
The code:
for i in tqdm_notebook(range(data.shape[0])):
print('BIN:',i)
fig = plt.figure(figsize=(15,4))
plt.tight_layout()
gs = gridspec.GridSpec(2,1)
ax1 = fig.add_subplot(gs[0, 0])
ax1.plot(match[window_begin:window_end],'k')
plt.vlines(i,-np.max(match[window_begin:window_end])*0.05,np.max(match[window_begin:window_end])*1.05,'r',linewidth=4,alpha=0.2)
ax1.set_xlim(0-1,post_bin_match_median[window_begin:window_end].shape[0])
ax1.set_ylim(-np.max(match[window_begin:window_end])*0.05,np.max(match[window_begin:window_end])*1.05)
plt.tick_params(axis='y', which='both', left=True, labelleft=False)
ax1.tick_params(axis='x', which='both', bottom=False, labelbottom=False)
plt.grid()
ax2 = fig.add_subplot(gs[1, 0])
fig.subplots_adjust(hspace=0.0)
ax2.plot(gp_mjds[:],gp_data[i,:],'k')
ax2.errorbar(remain, all[i,:], yerr=all_noise[i], fmt=".k", capsize=0);
ax2.fill_between(gp[:], gp2[i,:] - np.sqrt(gp_var[i,:]), gp2[i,:] + np.sqrt(gp_var[i,:]),color="k", alpha=0.2)
ax2.set_xlim(gp[0],gp[-1])
plot_y_min = np.minimum(np.min(gp2[:,:] - np.sqrt(gp_var[:,:])),np.min(all_profile_residuals[:,:]-y_noise))
plot_y_max = np.maximum(np.max(gp2[:,:] + np.sqrt(gp_var[:,:])), np.max(all[:,:]+y_noise))
ax2.set_ylim(plot_y_min,plot_y_max)
plt.grid()
plt.show()
plt.clf()
plt.close(fig);
The semi-colon would work if the typical output from the last line of the cell is what you are trying to suppress. As succinctly summarized by #kynan here, "The reason this works is because the notebook shows the return value of the last command. By adding ; the last command is "nothing" so there is no return value to show."
However, you have a loop inside a cell generating objects.
The culprit seems to be plt.clf(). Comment out that line or remove it from your code, and it should fix it.
Plus, I'd remove plt.show() as it isn't necessary when plt.clf() is removed, and I am seeing it being in the loop causing fig = plt.figure(figsize=(15,4)) to also show output text like you posted in your issue.
(I'll add for others looking at this later, that it is important have %matplotlib inline or %matplotlib notebook at the start of the cell (or at the start of a cell somewhere above this one.))
A complete guide on how to hide or remove content in Jupyter is available from the official documentation: https://jupyterbook.org/interactive/hiding.html#
For removing the single output line, you can tweak the command lines by adding a _ = [command ] assignment as suggested in this blog: https://www.tutorialguruji.com/python/suppress-output-in-matplotlib/.
The underscore there is a throwaway variable, actually an unidentified variable "when not in interactive mode". See the official Python documentation: https://docs.python.org/3.9/reference/lexical_analysis.html#reserved-classes-of-identifiers

Can you unprint a line in R?

I am writing up some data processing stuff and I wanted to have a concise progress status printing a fraction that updates over time on a single line in the console.
To get this done I wanted to have something like this
print(Initiating data processing...)
for(sample in 1:length(data)){
print(paste(sample,length(data),sep="/"))
process(data[[sample]])
#Unprint the bottom line in the console ... !!! ... !!!.. ?
}
Keeping the screen clean and what not. I don't quite know how to do it. I know that there is a R text progress bar but for utilities sake I'm looking for a little more control.
Thanks!
I think your best bet is to do exactly what the R text progress bar does, which is "\r to return to the left margin", as seen in the help file. You'll have to use cat instead of print because print ends with a newline.
cat("Initiating data processing...\n")
for(sample in 1:length(data)){
cat(sample, length(data), sep="/")
process(data[[sample]])
cat("\r")
}
cat("\n")

Resources