Tutorial by Examples: c

A random forest is a meta estimator that fits a number of decision tree classifiers on various sub-samples of the dataset and use averaging to improve the predictive accuracy and control over-fitting. A simple usage example: Import: from sklearn.ensemble import RandomForestClassifier Define tr...
git blame <file> will show the file with each line annotated with the commit that last modified it.
Sometimes repos will have commits that only adjust whitespace, for example fixing indentation or switching between tabs and spaces. This makes it difficult to find the commit where the code was actually written. git blame -w will ignore whitespace-only changes to find where the line really came fr...
Output can be restricted by specifying line ranges as git blame -L <start>,<end> Where <start> and <end> can be: line number git blame -L 10,30 /regex/ git blame -L /void main/, git blame -L 46,/void foo/ +offset, -offset (only for <end>) git blame -...
One of the uses of recursion is to navigate through a hierarchical data structure, like a file system directory tree, without knowing how many levels the tree has or the number of objects on each level. In this example, you will see how to use recursion on a directory tree to find all sub-directorie...
It is a good idea to maintain a web-scraping session to persist the cookies and other parameters. Additionally, it can result into a performance improvement because requests.Session reuses the underlying TCP connection to a host: import requests with requests.Session() as session: # all req...
Because LINQ uses deferred execution, we can have a query object that doesn't actually contain the values, but will return the values when evaluated. We can thus dynamically build the query based on our control flow, and evaluate it once we are finished: IEnumerable<VehicleModel> BuildQuery(i...
While RODBC is restricted to Windows computers with compatible architecture between R and any target RDMS, one of its key flexibilities is to work with Excel files as if they were SQL databases. require(RODBC) con = odbcConnectExcel("myfile.xlsx") # open a connection to the Excel file s...
First need to create a final static logger object: final static Logger logger = Logger.getLogger(classname.class); Then, call logging methods: //logs an error message logger.info("Information about some param: " + parameter); // Note that this line could throw a NullPointerException!...
The console for the primary version of Python can usually be opened by typing py into your windows console or python on other platforms. $ py Python 3.4.3 (v3.4.3:9b73f1c3e601, Feb 24 2015, 22:44:40) [MSC v.1600 64 bit (AMD64)] on win32 Type "help", "copyright", "credits&...
Python has a variety of command-line switches which can be passed to py. These can be found by performing py --help, which gives this output on Python 3.4: Python Launcher usage: py [ launcher-arguments ] [ python-arguments ] script [ script-arguments ] Launcher arguments: -2 : Launch ...
The Python console adds a new function, help, which can be used to get information about a function or object. For a function, help prints its signature (arguments) and its docstring, if the function has one. >>> help(print) Help on built-in function print in module builtins: print(.....
A simple static file server would look like this: package main import ( "net/http" ) func main() { muxer := http.NewServeMux() fileServerCss := http.FileServer(http.Dir("src/css")) fileServerJs := http.FileServer(http.Dir("src/js")) file...
The For Each loop construct is ideal for iterating all elements of a collection. Public Sub IterateCollection(ByVal items As Collection) 'For Each iterator must always be variant Dim element As Variant For Each element In items 'assumes element can be converted to a stri...
Sometimes you need to keep a linear (non-branching) history of your code commits. If you are working on a branch for a while, this can be tricky if you have to do a regular git pull since that will record a merge with upstream. [alias] up = pull --rebase This will update with your upstream so...
You can use the star * when writing a function to collect all positional (ie. unnamed) arguments in a tuple: def print_args(farg, *args): print("formal arg: %s" % farg) for arg in args: print("another positional arg: %s" % arg) Calling method: print_args(1, &...
You can define a function that takes an arbitrary number of keyword (named) arguments by using the double star ** before a parameter name: def print_kwargs(**kwargs): print(kwargs) When calling the method, Python will construct a dictionary of all keyword arguments and make it available in ...
A common use case for *args in a function definition is to delegate processing to either a wrapped or inherited function. A typical example might be in a class's __init__ method class A(object): def __init__(self, b, c): self.y = b self.z = c class B(A): def __init__(...
You can use a dictionary to assign values to the function's parameters; using parameters name as keys in the dictionary and the value of these arguments bound to each key: def test_func(arg1, arg2, arg3): # Usual function with three arguments print("arg1: %s" % arg1) print("a...
In this example a custom LAMP project development environment is created with Vagrant. First of all you will need to install Virtual Box and Vagrant. Then, create a vagrant folder in your home directory, open your terminal and change the current directory to the new vagrant directory. Now, execute...

Page 191 of 826