Posts Tagged ‘ python ’

Use recursion and gradient ascent to solve logistic regression in Python

May 21, 2014
By
Use recursion and gradient ascent to solve logistic regression in Python

This post was kindly contributed by DATA ANALYSIS - go there to comment and to read the full post. In his book Machine Learning in Action, Peter Harrington provides a solution for parameter estimation of logistic regression . I use pandas and ggplot to realize a recursive alternative. Comparing with the iterative method, the recursion costs more space but may bring...
Read more »

Tags: ,
Posted in SAS | Comments Off

Count large chunk of data in Python

April 30, 2014
By

This post was kindly contributed by DATA ANALYSIS - go there to comment and to read the full post. The line-by-line feature in Python allows it to count hard disk-bound data. The most frequently used data structures in Python are list and dictionary. Many cases the dictionary has advantages since it is a basically...
Read more »

Tags:
Posted in SAS | Comments Off

SAS vs. Python for data analysis

March 27, 2014
By

To perform data analysis efficiently, I need a full stack programming language rather than frequently switching from one language to another. That means — this language can hold large quantity of data, manipulate data promptly and easily (e.g. if-then-else; iteration), connect to various data sources such as relational database and Hadoop, apply some statistical...
Read more »

Tags: ,
Posted in Uncategorized | Comments Off

Use a list as stack/queue in Python

November 30, 2013
By

Python does not have native structures for stack or queue, which could otherwise be manually implemented if needed. However, list in Python is an easy alternative as stack or queue. Stack and queue share the same method append(), while stack uses pop() and queue applies pop(0) distinctively.

1. Valid Parentheses

Given a string containing just the characters ‘(‘, ‘)’, ‘{‘, ‘}’,...
Read more »

Tags:
Posted in Uncategorized | Comments Off

Sorting in Python

November 17, 2013
By

#-------------------------------------------------------------------------------
# Name: Methods of sorting
# Purpose: implements the sortings mentioned by Robert Sedgewick and
# Kevin Wayne, Algorithms 4ed
#
#-------------------------------------------------------------------------------

def selection_sort(a):
for i in range(len(a)):
...
Read more »

Tags:
Posted in Uncategorized | Comments Off

Use hash to decrease complexity

November 13, 2013
By

  • Unique String
#-------------------------------------------------------------------------------
# Name: Unique String
# Purpose: Find if a string is unique or not
#
#-------------------------------------------------------------------------------

# Solution 1
def is_unique(s):
a = *256
for n in s:
# Use the ord() function to find the ASCII value of a character
if a:
return False # jump out of the...
Read more »

Tags:
Posted in Uncategorized | Comments Off

Use Python to solve math questions (1)

November 10, 2013
By

  1. Translate the numbers to an array of integer to avoid stack overflow
  2. Use while to control flow once the iteration times are unknown
  3. Apply % and \ to retrieve digits from a integer
  4. Be careful of the direction of the iteration

  • Reverse Integer
Reverse digits of an integer.
Example1: x = 123, return 321
Example2: x = -123, return -321
def rev_int(a):
negative = False
...
Read more »

Tags:
Posted in Uncategorized | Comments Off

Use max/min functions to avoid conditions

November 4, 2013
By
Use max/min functions to avoid conditions

The functions such as max() and min() play a role such as
if a < b:
a = b
Using them in programing will bring flexibility and simply coding.

1. Best Time to Buy and Sell Stock Total

Say you have an array for which the ith element is the price of a given stock...
Read more »

Tags:
Posted in Uncategorized | Comments Off

Proc-x is looking for sponsors!

Dear readers, proc-x is looking for sponsors who would be willing to support the site in exchange for banner ads in the right sidebar of the site. If you are interested, please e-mail me at: [email protected]

Welcome!

SAS-X.com offers news and tutorials about the various SAS® software packages, contributed by bloggers. You are welcome to subscribe to e-mail updates, or add your SAS-blog to the site.

SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS Institute Inc. in the USA and other countries. ® indicates USA registration.